Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Warning: This is highly unannotated and thus not readable.
A = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-'
K = [
"0000000008258240093",
"00000032059146620",
"0000059424680571",
"00000016501626909",
"000000010391056299",
"00000000039819521706",
"000063129310438"
]
K = list(map(lambda x: int(x), K))
def revert(q):
u = 0
for c in q:
u = 26*u + A.index(c)
return u
def revert2(q):
u, _ = q
return ''.join([A[(u>>(6*i+6)) & 0x3f] for i in range(5)][::-1])
candidates = \
'bcwtdes dqoagnv hqxmvkq jfntbvq nanqyku pqeytpx pruxdbh sipootq'.split(' ')
results = []
for candidate in candidates:
k = revert(candidate)
for i in range(k, 2**36, 26**7):
results.append(i)
# union
for i in range(5):
# res = [(u_before_xors, u_after_xors), ...]
res = sorted([(fu ^ 1763 ^ K[i], fu) for fu in results])
res = filter(lambda u: ((u[0]>>0)&0x3f) == 0, res)
res = filter(lambda u: ((u[0]>>6)&0x3f) == A.index('union'[i]), res)
res = list(res)
print(i, list(map(revert2, res)))
'''
0 ['h4shu']
1 ['C0lln']
2 ['1zioi']
3 ['n_m4o']
4 ['ke5_n']
union{h4shC0ll1zion_m4ke5_????????}
'''
# {
for i in range(5, 6):
# res = [(u_before_xors, u_after_xors), ...]
res = sorted([(fu ^ 1763 ^ K[i], fu) for fu in results])
res = filter(lambda u: ((u[0]>>0)&0x3f) == 0, res)
res = filter(lambda u: ((u[0]>>6)&0x3f) == 0x3f, res)
# In hexa, A.indexOf('{') == -1.
# This may cause rounding issue and the fourth character should be increased by one.
res = list(res)
print(i, list(map(revert2, res)))
'''
5 ['HAXD-']
^--- This should be an E as line 63 suggests
union{h4shC0ll1zion_m4ke5_HAXE????}
'''
# h
for i in range(6, 7):
# res = [(u_before_xors, u_after_xors), ...]
res = sorted([(fu ^ 1763 ^ K[i], fu) for fu in results])
res = filter(lambda u: ((u[0]>>0)&0x3f) == 0, res)
res = filter(lambda u: ((u[0]>>6)&0x3f) == A.index('h'), res)
res = list(res)
print(i, list(map(revert2, res)))
'''
6 ['_sadh']
union{h4shC0ll1zion_m4ke5_HAXE_sad}
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment