2026-11-05 11:10:32 +01:00
|
|
|
import base64
|
2026-11-05 11:19:40 +01:00
|
|
|
from Crypto.Util.number import long_to_bytes
|
|
|
|
|
from pwn import xor
|
2026-11-05 11:10:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Challenge intro-1
|
|
|
|
|
def int_to_ascii(input: [int]) -> str:
|
|
|
|
|
res = bytearray()
|
|
|
|
|
for i in input:
|
|
|
|
|
res += i.to_bytes()
|
|
|
|
|
return res.decode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Challenge intro-2
|
|
|
|
|
def hex_to_ascii(input: str) -> str:
|
|
|
|
|
return bytes.fromhex(input).decode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Challenge intro-3
|
2026-11-05 11:52:31 +01:00
|
|
|
def hex_to_b64(input: str) -> str:
|
|
|
|
|
return base64.b64encode(bytes.fromhex(input)).decode("utf-8")
|
2026-11-05 11:10:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Challenge intro-4
|
|
|
|
|
def int_to_message_rsa(input: int) -> str:
|
|
|
|
|
return long_to_bytes(input)
|
2026-11-05 11:19:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Challenge intro-5
|
|
|
|
|
def xor_13(input: str) -> str:
|
|
|
|
|
return xor(input, 13).decode("utf-8")
|
2026-11-05 11:27:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Challenge intro-6
|
|
|
|
|
def unxor_flag(
|
|
|
|
|
key1: str, key2_key1: str, key2_key3: str, flag_key1_key3_key2: str
|
|
|
|
|
) -> str:
|
|
|
|
|
key_1 = int_to_message_rsa(key1)
|
|
|
|
|
key_2 = xor(int_to_message_rsa(key2_key1), key_1)
|
|
|
|
|
key_3 = xor(int_to_message_rsa(key2_key3), key_2)
|
|
|
|
|
flag = xor(xor(xor(int_to_message_rsa(flag_key1_key3_key2), key_1), key_2), key_3)
|
|
|
|
|
return flag.decode("utf-8")
|
2026-11-05 11:30:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Challenge intro-7
|
|
|
|
|
def mystery_xor(input: int):
|
|
|
|
|
str_input = int_to_message_rsa(input)
|
|
|
|
|
for i in range(1, 128):
|
|
|
|
|
candidate = xor(str_input, i).decode("utf-8")
|
|
|
|
|
if candidate.startswith("crypto"):
|
|
|
|
|
return candidate
|
2026-11-05 11:52:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Challenge intro-6
|
|
|
|
|
def mystery_key(input: int):
|
|
|
|
|
str_input = int_to_message_rsa(input)
|
|
|
|
|
key = xor(str_input, "crypto{1").decode("utf-8")[:8]
|
|
|
|
|
key = key + key + key + key + key + key + key + key + key + key + key + key
|
|
|
|
|
return xor(str_input, key[: len(str_input)]).decode("utf-8")
|