How easy it is to convert a number, for example. 0x616263, equivalent 6382179in base 10, to a string by dividing the number by consecutive bytes? So, the above example should convert to 'abc'.
I experimented with Array.pack , but can't figure out how to get it to convert more than one byte to a number, for example. [0x616263].pack("C*")returns 'c'. I also tried 0x616263.to_s(256), but this throws an ArgumentError: invalid value. I think he needs some kind of coding information?
(Note. The other data types in the type packet Nwork with the above example, but only because it fits within 4 bytes, therefore, for example, [0x616263646566].pack("N")gives cdef, not abcdef)
This question is vaguely similar to this , but not really. Also, I kind of figured out how to get the hexadecimal representation string from a character string using "abcde".unpack("c*").map{|c| c.to_s(16)}.join(""), which gives '6162636465'. I basically want to go back.
I do not think this is an XY problem , but in case this is the case - I am trying to convert the number I "ve decoded from RSA to a string of characters.
Thanks for any help. I'm not too experienced with Ruby. I would also be interested in a Python solution (for fun), but I don't know if there is a right to add tags for two separate programming languages to this question.
source
share