0

I want to decrypt some DES3 encrypted messages from other aplication. The problem is, that ruby uses backslash notation, which looks like that:

\xE7B8\xCF\xFC\x9Fu\fkΖ\xB3\u001As\x93\xFF

and I'm receiving something like that:

6613E58F24183FC60B2BB1A2EE9DA61A

I now how to use encryption in ruby, but I have no idea how to deal when I got notation as above. Do I need to convert it somehow? Any help would be greatly appreciated.

zachar
  • 1,085
  • 1
  • 11
  • 18
  • `\xE7B8\xCF\xFC\x9Fu\fkΖ\xB3\u001As\x93\xFF` is a specification of character encoded data. This is not what you want, what you want is bytes. So you should use a hexadecimal decoder. – Maarten Bodewes Jan 28 '13 at 17:59

2 Answers2

1

String#unpack should do the job:

> str = "\xE7B8\xCF\xFC\x9Fu\fkΖ\xB3\u001As\x93\xFF" # Use double-quotes
=> "\xE7B8\xCF\xFC\x9Fu\fkΖ\xB3\u001As\x93\xFF"
> str.unpack('H*')
=> ["e74238cffc9f750c6bce96b31a7393ff"]

The inverse workaround would be:

> str = ["6613E58F24183FC60B2BB1A2EE9DA61A"]
> str.pack 'H*'
=> "f\x13\xE5\x8F$\x18?\xC6\v+\xB1\xA2\xEE\x9D\xA6\x1A"
ichigolas
  • 7,595
  • 27
  • 50
  • I would vote this up, but it seems to be the wrong way around, the question was to go from `e74238cffc9f750c6bce96b31a7393ff` to `\xE7B8\xCF\xFC\x9Fu\fkΖ\xB3\u001As\x93\xFF`. I do think however that the user should go from `6613E58F24183FC60B2BB1A2EE9DA61A` to an internal representation of a byte array / octet string. – Maarten Bodewes Jan 28 '13 at 19:14
  • Edited for the inverse case. Sincerely, I'm not a guru at encodings, just offering an option. – ichigolas Jan 28 '13 at 21:13
0

First notation is a string representation of raw binary data. Second one - is hex-encoded data, i.e. each byte is represented as two hex chars.

Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48