34 lines
859 B
Python
34 lines
859 B
Python
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)
|