zachar
zachar

Reputation: 1095

DES3 and differences between notations

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.

Upvotes: 0

Views: 95

Answers (2)

ichigolas
ichigolas

Reputation: 7725

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"

Upvotes: 1

Nickolay Olshevsky
Nickolay Olshevsky

Reputation: 14160

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.

Upvotes: 0

Related Questions