1

I have to encrypt a message with a "zero padding" in OpenSSL. I have read here (Use Zero Padding in OpenSSL?) that if I want a "zero padding", I have to add myself the 0. So here we go.

I'm trying to pad the "A" message for exemple. But there is one thing I don't understand.

   ["a"].pack("b*").each_byte { |b| printf("%08b", b) }
   => "00000000"
   ["c"].pack("b*").each_byte { |b| printf("%08b", b) }
   => "00000000"

Why the results are equal ? "a" and "c" are 2 differents strings, but the binary is equal ?

Community
  • 1
  • 1
elhostis
  • 1,067
  • 14
  • 32

1 Answers1

1

pack has a directive for zero-padding:

["a"].pack("a2") 
#=> "a\x00"`

As for your question, you want to unpack a string, not pack an array:

'a'.unpack('b*')
#=> ["10000110"]
'c'.unpack('b*')
#=> ["11000110"]
Michael Kohl
  • 66,324
  • 14
  • 138
  • 158