NahamCon 2022, XORROX
-
Cryptography
Soal¶
xorrox=[1, 209, 108, 239, 4, 55, 34, 174, 79, 117, 8, 222, 123, 99, 184, 202, 95, 255, 175, 138, 150, 28, 183, 6, 168, 43, 205, 105, 92, 250, 28, 80, 31, 201, 46, 20, 50, 56]
enc=[26, 188, 220, 228, 144, 1, 36, 185, 214, 11, 25, 178, 145, 47, 237, 70, 244, 149, 98, 20, 46, 187, 207, 136, 154, 231, 131, 193, 84, 148, 212, 126, 126, 226, 211, 10, 20, 119]
#!/usr/bin/env python3
import random
with open("flag.txt", "rb") as filp:
flag = filp.read().strip()
key = [random.randint(1, 256) for _ in range(len(flag))]
xorrox = []
enc = []
for i, v in enumerate(key):
k = 1
for j in range(i, 0, -1):
k ^= key[j]
xorrox.append(k)
enc.append(flag[i] ^ v)
with open("output.txt", "w") as filp:
filp.write(f"{xorrox=}\n")
filp.write(f"{enc=}\n")
Jawaban¶
Ide enkripsi
key = [random1, random2, random3, ...]
flag = 'flag{selamat}'
enc[0] = flag[0] ^ key[0]
enc[1] = flag[1] ^ key[1]
enc[2] = flag[2] ^ key[2]
dst...
k = 1
xorrox[0] = k
xorrox[1] = k ^ key[1]
xorrox[2] = k ^ key[2] ^ key[1]
xorrox[3] = k ^ key[3] ^ key[2] ^ key[1]
dst...
dengan memanfaatkan
diperoleh ide dekripsi
xorrox[1] = k ^ key[1]
key[1] = k ^ xorrox[1]
xorrox[2] = k ^ key[2] ^ key[1]
key[2] = k ^ key[1] ^ xorrox[2]
dst...
hasil
key_awal = []
xorrox=[1, 209, 108, 239, 4, 55, 34, 174, 79, 117, 8, 222, 123, 99, 184, 202, 95, 255, 175, 138, 150, 28, 183, 6, 168, 43, 205, 105, 92, 250, 28, 80, 31, 201, 46, 20, 50, 56]
for i in range(0,len(xorrox)):
k = 1
for j in key_awal:
k ^= j
k ^= xorrox[i]
key_awal.append(k)
enc=[26, 188, 220, 228, 144, 1, 36, 185, 214, 11, 25, 178, 145, 47, 237, 70, 244, 149, 98, 20, 46, 187, 207, 136, 154, 231, 131, 193, 84, 148, 212, 126, 126, 226, 211, 10, 20, 119]
flag = ''
for i in range(len(enc)):
flag += chr(enc[i]^key_awal[i])
print(flag)