1

According to the specs they should be same length, and a string of length 36 should translate to a string of length 48, for example:

bin = "123456789012345678901234567890123456"
[49] pry(main)> [bin].pack("m").length
=> 49
[50] pry(main)> [bin].pack("u").length
=> 50
[54] pry(main)> [bin].pack("m")
=> "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2\n"
[55] pry(main)> [bin].pack("u")
=> "D,3(S-#4V-S@Y,\#$R,S0U-C<X.3`Q,C,T-38W.#DP,3(S-#4V\n"

Compensating for the "funny newline" we get the proper length in the base64 encoding (the pack('m') variant), but I don't know how to get the line length right in the uuencoding (the pack('u') variant).

I really need that uuencoded string to be 48 chars long :) what's the issue here?

Update

I did my own uuencode implementation, created a method that generates bitmap and then split the bitmap etc to make a uuencode implementation, as the provider of the specification helpfully explained in the spec

def to_bitmap bytes
  bytes.scan(/./).map{|b| b.ord.to_s(2).rjust(8, "0")}.join
end

[5] pry(main)> to_bitmap(str).scan(/.{6}/).map{|b| (from_bitmap("00"+b).ord+0x20).chr }.join
=> ",3(S-#4V-S@Y,\#$R,S0U-C<X.3 Q,C,T-38W.#DP,3(S-#4V"
[6] pry(main)> to_bitmap(str).scan(/.{6}/).map{|b| (from_bitmap("00"+b).ord+0x20).chr }.join.length
=> 48

and I assume this is the good thing, it's kind of like uuencode, but differs in a couple of places:

 ,3(S-#4V-S@Y,\#$R,S0U-C<X.3 Q,C,T-38W.#DP,3(S-#4V
D,3(S-#4V-S@Y,\#$R,S0U-C<X.3`Q,C,T-38W.#DP,3(S-#4V\n

Wierd, I guess it's the specification I'm implementing is using a "uuencode" and not quite uuencode though they claim that generic software libraries support this format, am I missing something or does this seem like bullshit and workaround for somebodies half-assed implementation of uuencode?

bbozo
  • 7,075
  • 3
  • 30
  • 56
  • 3
    Unlike base64, uuencode doesn't guarantee that encoded form will be_exactly_ 4/3 times as big. Only that it will be _at least_ 4/3 times as big (it may have additional tags or whatever). This is what I learned from reading wikipedia for 5 minutes :) – Sergio Tulentsev Nov 28 '16 at 19:19
  • :) I have a file format specification saying that my 36-length string needs to become a 48-length string and it just doesn't want to accept 49 :) – bbozo Nov 28 '16 at 19:23
  • 1
    well, good luck with that. I tried a few encoders online and they all generated an even bigger string (that newline PLUS a single quote afterwards). – Sergio Tulentsev Nov 28 '16 at 19:25
  • Yeah, very funny, I just tried out my own implementation based on the file format specification I'm following, and it gets funkier on every step. Thanks for your help :) – bbozo Nov 28 '16 at 19:42
  • 1
    in SO format, it'd be better to post your own answer and then accept that answer. It'll register the question, and it's semantics, as having an answer – New Alexandria May 18 '20 at 03:19

0 Answers0