From 209ca55ada97dd1a546bc0b1f05e740c968b4a0d Mon Sep 17 00:00:00 2001 From: Abel Stuker Date: Mon, 25 Nov 2024 22:30:51 +0100 Subject: [PATCH] feat: add magic-byte challenge --- magic-byte/README.md | 14 ++++++++++++++ magic-byte/SOLUTION.md | 15 +++++++++++++++ magic-byte/create_magic_byte.py | 33 +++++++++++++++++++++++++++++++++ magic-byte/magic_byte.txt | 1 + 4 files changed, 63 insertions(+) create mode 100644 magic-byte/README.md create mode 100644 magic-byte/SOLUTION.md create mode 100644 magic-byte/create_magic_byte.py create mode 100644 magic-byte/magic_byte.txt diff --git a/magic-byte/README.md b/magic-byte/README.md new file mode 100644 index 0000000..952a8fc --- /dev/null +++ b/magic-byte/README.md @@ -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 diff --git a/magic-byte/SOLUTION.md b/magic-byte/SOLUTION.md new file mode 100644 index 0000000..829bc16 --- /dev/null +++ b/magic-byte/SOLUTION.md @@ -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!} diff --git a/magic-byte/create_magic_byte.py b/magic-byte/create_magic_byte.py new file mode 100644 index 0000000..25598f4 --- /dev/null +++ b/magic-byte/create_magic_byte.py @@ -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) diff --git a/magic-byte/magic_byte.txt b/magic-byte/magic_byte.txt new file mode 100644 index 0000000..3eab51a --- /dev/null +++ b/magic-byte/magic_byte.txt @@ -0,0 +1 @@ +flag: 858b8f988ab7a4a9a0a0a393aaa0adabedb1 \ No newline at end of file