feat: add magic-byte challenge

This commit is contained in:
Abel Stuker 2024-11-25 22:30:51 +01:00
parent 79072f30c9
commit 209ca55ada
4 changed files with 63 additions and 0 deletions

14
magic-byte/README.md Normal file
View File

@ -0,0 +1,14 @@
# Magic Byte
## Text
Hi! I encrypted my flag with some awesome magic. ... Lore ... Lore ...
Figure it out :)
## Files
magic_byte.txt
## How to Deploy
N/A

15
magic-byte/SOLUTION.md Normal file
View File

@ -0,0 +1,15 @@
## Difficulty
Easy, because it is easy.
## Category
Crypto
## How To Solve
Just bruteforce the magic byte, xoring the ciphertext with the byte.
## Flag
IGCTF{hello_flag!}

View File

@ -0,0 +1,33 @@
magic = 0xCC
flag = "IGCTF{hello_flag!}"
def xor_string_with_byte(input_str, xor_byte):
# Convert the input string to bytes
input_bytes = input_str.encode()
# XOR each byte in the string with the given byte
xor_result = bytes([b ^ xor_byte for b in input_bytes])
# Convert the XOR result to a hex string
hex_result = xor_result.hex()
return hex_result
def reverse_xor(hex_str, xor_byte):
# Convert the hex string back to bytes
xor_bytes = bytes.fromhex(hex_str)
# XOR each byte in the result with the same XOR byte
original_bytes = bytes([b ^ xor_byte for b in xor_bytes])
# Convert the result back to the original string
original_str = original_bytes.decode()
return original_str
result = xor_string_with_byte(flag, magic)
print(result)
original = reverse_xor(result, magic)
print(original)

View File

@ -0,0 +1 @@
flag: 858b8f988ab7a4a9a0a0a393aaa0adabedb1