Score:0

Why is this code working

de flag

I was doing some introductory challenges at CryptoHack and one of the challenges, more precisely it was Favourite Byte, XOR with a single byte.

I did my solution with XORing given string and single key iterated over 256 integers till I find something that looks like "flag".

Then I looked for submitted solutions and one of the solutions was:

input_str = bytes.fromhex('73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d')

key = input_str[0] ^ ord('c')
print(''.join(chr(c ^ key) for c in input_str))

The part that is giving me trouble is the third line or assignment of the key variable. Why is this key working? In other words, how did he find it? My best guess is he did exactly what I did earlier(iterated over 256 integers) and once he found it he modified his code.

Any help will be greatly appreciated!

kelalaka avatar
in flag
They did find it on their computer and only submitted this. It is CryptoHack's problem that they accept this.
Score:4
us flag

There's nothing very difficult going on here.

As the website says, its flags are usually in the format crypto{y0ur_f1rst_fl4g}. It's thus very likely that the first character of the flag you're trying to retrieve is c, which means that the XOR key must be the ASCII value of c (0x63) XORed with the first character of the ciphertext (0x73).

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.