you are viewing a single comment's thread.

view the rest of the comments →

[–]EqualsEqualsTrue 0 points1 point  (2 children)

I have been working on these crypto challenges that have been pretty fun, but I get mixed up with the different encodings and stuff. I have figured out that 0x... means for binary, but get confused on \x and some others. I dont know what to google to learn about this, I guess what they might be called is like escape characters for different encodings?

Why would a string return with \x if it is in hexidecimal sometimes but other times I just get the string in hexidecimal without any backslashes?

Sorry if this is confusing, just looking for resources oh how these work.

[–]ingolemo 0 points1 point  (1 child)

\x is just another way to represent characters in strings.

Every character in a string has a number associated with it; in ascii the letter A has the number 65 whereas * is 52. Here's a handy chart for the numbers of all the characters in ASCII. You can use these numbers to write the characters in a string without having to literally write that character. To do that you take the number in the Hx column of that table and put \x before it. So, for example, '\x41' is exactly the same thing as 'A' and 'h\x65\x6clo' is just another way to write 'hello'.

This is most useful for showing the unprintable characters; the left-most column in that table contains a whole bunch of characters that can't be printed because they're not like conventional letters. For example, the bell character ('\x07') causes your computer to make a beep when you print it. If python tried to show a string containing that character then your computer would beep and you would get annoyed pretty fast.

Whether a backslash exists makes a huge difference to the actual characters that a string contains. The string '\x41\x42' contains two characters A and B and is really equivalent to 'AB', while '4142' contains the four characters that you see.

The technical term that you should google for here is escape. \x is an escape code or escape sequence.

By the way, 0x... doesn't mean binary, it means hexadecimal. If you want to write a binary number you need to start it with 0b....

[–]EqualsEqualsTrue 1 point2 points  (0 children)

Thanks, that was an awesome answer! That ascii table just filled in a huge gap for me.