Tuesday, August 30, 2016

Cryptanalysis / Encoding - ASCII

Link to the challenge: Encoding - ASCII

Ok, so this challenge is really simple, so we will use it as an excuse to learn a bit more about ASCII. The challenge consists of decoding this string:

 4C6520666C6167206465206365206368616C6C656E6765206573743A203261633337363438316165353436636436383964356239313237356433323465  
What is ASCII ?
ASCII is a text encoding scheme that allow to display text.
Each character is encoded on 1 byte, and this is a standard, so in any computer you will use, the same character will correspond to the same value.
Here is the ASCII table, matching each character to it's value, coded on different bases (decimal, hexadecimal, octal):
You can see, for example, that the character 'A' is represented by the value 65 in decimal, but also by the value 41 in hexadecimal, and 101 in octal.
We can easily verify that all of these representations are equivalent, by converting them to the decimal base:
  (hexadecimal: 4*16 + 1*1 = 65)
  (octal: 1*64 + 0*8 + 1*1 = 65)
In order to decode an ASCII character based on it's value, you need to know which base has been used to encode it (decimal, hexadecimal, octal).
In 70% of the time, characters are encoded in hexadecimal, 29.9% in decimal, and 0.1% in octal (I never met such encoding yet).
We noticed that in our string we have to decode, some characters are letters, so if we assume this is an encoded ASCII string (as the title of the challenge suggests it), it cannot be decimal or octal, because both of this bases only use digits. The only base left, is hexadecimal, which uses digits and letters, up to F.
You now need to find a tool that can convert hexadecimal data to ascii.
Tips: Google is your friend, as well as Wikipedia :)

Bonus: If you want to do some exercise, you can try to create a small program to decode it.
Here are an idea of how to do it:

 1) Put the encoded string in a variable (by input or hard coded)  
 2) Loop until the end of the string  
 3) Read the characters of the string 2 by 2  
 4) Convert the group of 2 characters to a number (look at strtol() in C, int() in python, etc...)  
 5) Pass your number to a function that can convert your value to ASCII (convert to char in C, chr() in python)  
 6) Append the result to a string you will have initialized empty at the beginning  
 7) When the loop is done, print your string where you append all ASCII characters 
 8) You should now have decoded your ASCII string, congratz. 

1 comment: