Receive and convert stream from remote server to string

0

I am making a script that receives a stream, in hexadecimal format, from a remote server via TCP connection, in order to break its encryption and read an ASCII message that is in it. My goal is to read this stream, and convert it to string, in order to run the script I made (which considers as input only strings).

I'm new to Ruby. I can not even read the stream that comes to my program. I can, through a website provided for this challenge, view the packets that leave the server. They look like this:

003B60558EB661BC55D2305E4A8AC07E6D518ABEE7A2BFE7B7B2A5E7B6B2AEBDE7A4B5A8B0A3E7A0A6B1A2E7ADA8BEA1B2ABE7B3AFA6A9ACB4E901

And I have received this in my terminal (in attempts to at least read the stream):

7�����焉(��hX@FB^T\[NSVQC]BZG^YPMRUEVDARO

How to read this stream, convert it to its normal normal format and finally convert it to string?

    
asked by anonymous 08.03.2015 / 00:45

1 answer

0

To convert the stream to string you can use the following one-liner:

"<seu stream hex>".split('').each_slice(2).map {|char| char.join.hex.chr }.join

It's not a fancy solution, but it's enough to fill your need.

As for the TCP socket connection part and reading packets from the server, take a look at the TCPSocket class of the Ruby default library (the latest version, 2.2.1, can be found here: link ).

    
20.03.2015 / 06:15