Favourite byte - Cryptohack writeup
Challenge
For the next few challenges, you'll use what you've just learned to solve some more XOR puzzles.
I've hidden some data using XOR with a single byte, but that byte is a secret. Don't forget to decode from hex first.
In challenge itself, it is given that above value ix XOR'd with any bytes. But we don't know about that bytes. Is there anything else that we knew ???? Yes!! that is the format of the flag, we know that flag starts with the characters crypto{.
We have to perform two things, 1- decode from hex, 2- find thoes bytes
There are various ways to solve this challenge, some of them are given below
Cyberchef :
- Open the website Cyberchef.
- 1. Paste the hex value given in challenge.
- 2. Choose the recipes From Hex then XOR Bruteforce
- 3. We know starting part of flag, type that out in Crib (known plaintext string)
- 4. It would look somthing like following crypto{0x10_15_my_f4v0ur173_by7e}
Using Python :
from pwn import xor
hx = bytes.fromhex('73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d')
for i in range(50):
result = xor(hx,i)
if chr(result[0]) == "c":
print(f'Key is : {i}, Flag is : {result}') # Output: Key is : 16, Flag is : b'crypto{0x10_15_my_f4v0ur173_by7e}'
I am using PWN library, which provide alot of cryptography related functions who made our life easier. xor() function is one of them. In above code we looped through a range of number and XORed decoded hex with each number, and we know the first charecters of the flag so we checked that first latter is "c" or not. If it is then print it.
We get the flag at 17 but if we didn't, then we have to try somthing else, like: characters
Final flag: crypto{0x10_15_my_f4v0ur173_by7e}