General - XOR
XOR Starter
"Given the string label, XOR each character with the integer 13. Convert these integers back to a string and submit the flag as crypto{new_string}."
The following script should do the trick of printing the flag.
#!/usr/bin/env python3
def xor_encrypt(s: str, key: int) -> str:
"""
Encrypts a string using XOR with a key.
"""
new_string = ""
for c in s:
new_string += chr(ord(c) ^ key)
return new_string
def main():
s = "label"
key = 13
encrypted_string = xor_encrypt(s, key)
print("crypto{{{}}}".format(encrypted_string))
if __name__ == "__main__":
main()
XOR Properties
We get the following outputs where three random keys have been XOR'd together and with the flag:
The flag is in the last line. It is xored with KEY1, KEY2 and KEY3. Thus, all we need to do is to xor that line with all these keys. Lines 1 and 3 contains those combinations.
That is, KEY1 ^ KEY2 ^ KEY3 ^ FLAG ^ KEY1 ^ KEY3 ^ KEY2 = FLAG
Favourite byte
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.
73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d"
We know that the flag starts with 'c' as it follows the format crypto{flag}.
So, to find the one byte key we can xor the first byte of the string with the int value of 'c'.
You either know, XOR you don't
"I've encrypted the flag with my secret key, you'll never be able to guess it.
0e0b213f26041e480b26217f27342e175d0e070a3c5b103e2526217f27342e175d0e077e263451150104"
This challenge is similar to the previous one. We start with the fact that we know the flag start like this crypto{.
Last updated