XtraORdinary
This commit is contained in:
43
xtraordinary/encrypt.py
Executable file
43
xtraordinary/encrypt.py
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
with open('flag.txt', 'rb') as f:
|
||||||
|
flag = f.read()
|
||||||
|
|
||||||
|
with open('secret-key.txt', 'rb') as f:
|
||||||
|
key = f.read()
|
||||||
|
|
||||||
|
def encrypt(ptxt, key):
|
||||||
|
ctxt = b''
|
||||||
|
for i in range(len(ptxt)):
|
||||||
|
a = ptxt[i]
|
||||||
|
b = key[i % len(key)]
|
||||||
|
ctxt += bytes([a ^ b])
|
||||||
|
return ctxt
|
||||||
|
|
||||||
|
ctxt = encrypt(flag, key)
|
||||||
|
|
||||||
|
random_strs = [
|
||||||
|
b'my encryption method',
|
||||||
|
b'is absolutely impenetrable',
|
||||||
|
b'and you will never',
|
||||||
|
b'ever',
|
||||||
|
b'ever',
|
||||||
|
b'ever',
|
||||||
|
b'ever',
|
||||||
|
b'ever',
|
||||||
|
b'ever',
|
||||||
|
b'break it'
|
||||||
|
]
|
||||||
|
|
||||||
|
for random_str in random_strs:
|
||||||
|
for i in range(randint(0, pow(2, 8))):
|
||||||
|
for j in range(randint(0, pow(2, 6))):
|
||||||
|
for k in range(randint(0, pow(2, 4))):
|
||||||
|
for l in range(randint(0, pow(2, 2))):
|
||||||
|
for m in range(randint(0, pow(2, 0))):
|
||||||
|
ctxt = encrypt(ctxt, random_str)
|
||||||
|
|
||||||
|
with open('output.txt', 'w') as f:
|
||||||
|
f.write(ctxt.hex())
|
||||||
1
xtraordinary/output.txt
Executable file
1
xtraordinary/output.txt
Executable file
@@ -0,0 +1 @@
|
|||||||
|
57657535570c1e1c612b3468106a18492140662d2f5967442a2960684d28017931617b1f3637
|
||||||
57
xtraordinary/sol.py
Executable file
57
xtraordinary/sol.py
Executable file
@@ -0,0 +1,57 @@
|
|||||||
|
#!python3
|
||||||
|
from pwn import *
|
||||||
|
from itertools import chain, combinations
|
||||||
|
|
||||||
|
choice = 6
|
||||||
|
length = 7
|
||||||
|
|
||||||
|
def powerset(iterable):
|
||||||
|
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
|
||||||
|
s = list(iterable)
|
||||||
|
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
|
||||||
|
|
||||||
|
log.info("reading file")
|
||||||
|
with open("output.txt", 'r') as f:
|
||||||
|
c = int(f.read().strip(), 16)
|
||||||
|
log.info("read in cyphertext: {:x}".format(c))
|
||||||
|
|
||||||
|
c = pack(c, 'all', 'big', False)
|
||||||
|
|
||||||
|
random_strs = [
|
||||||
|
b'my encryption method',
|
||||||
|
b'is absolutely impenetrable',
|
||||||
|
b'and you will never',
|
||||||
|
b'ever',
|
||||||
|
b'break it'
|
||||||
|
]
|
||||||
|
|
||||||
|
def decrypt(ptxt, key):
|
||||||
|
ctxt = b''
|
||||||
|
for i in range(len(ptxt)):
|
||||||
|
a = ptxt[i]
|
||||||
|
b = key[i % len(key)]
|
||||||
|
ctxt += bytes([a ^ b])
|
||||||
|
return ctxt
|
||||||
|
|
||||||
|
log.info("generating key candidates...")
|
||||||
|
i = 0
|
||||||
|
candidates = []
|
||||||
|
for ss in powerset(random_strs):
|
||||||
|
_c = c
|
||||||
|
for s in ss:
|
||||||
|
_c = decrypt(_c, s)
|
||||||
|
_c = decrypt(_c, b'picoCTF{')
|
||||||
|
_c = _c.decode()
|
||||||
|
if _c[0:8].isprintable():
|
||||||
|
log.indented("{:2}: {}".format(i, _c[0:8]))
|
||||||
|
candidates.append((_c[0:8], ss))
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
key = candidates[choice][0][0:length].encode()
|
||||||
|
decrypt_set = candidates[choice][1]
|
||||||
|
log.success(key.decode())
|
||||||
|
for word in decrypt_set:
|
||||||
|
c = decrypt(c, word)
|
||||||
|
c = decrypt(c, key)
|
||||||
|
log.success("flag found: {}".format(c))
|
||||||
|
|
||||||
Reference in New Issue
Block a user