Skip to content

Instantly share code, notes, and snippets.

@gynvael
Created February 5, 2023 07:58
Show Gist options
  • Select an option

  • Save gynvael/1ee0c829d3987271237062d7b90d2fe2 to your computer and use it in GitHub Desktop.

Select an option

Save gynvael/1ee0c829d3987271237062d7b90d2fe2 to your computer and use it in GitHub Desktop.
BBCTF 2023 Visionary Cipher solver
#!/usr/bin/python3
# BBCTF 2023 Visionary Cipher solver by Gynvael Coldwind
from string import ascii_lowercase, digits
from random import choices
from hashlib import md5
import sys
alphabets = ascii_lowercase + digits + "_{}"
def pos(ch):
return alphabets.find(ch)
hash = '17382b1a9caad37bd127f2a7984ccbb9'
C = 'h50k8kbq{u}1qb_z1apvnfxqboh}vp30qrbbxs'
def known(idx, plaintext):
p1 = pos(C[idx])
p2 = pos(plaintext)
return (p1 - p2) % len(alphabets)
key = [
known(0, 'f'),
known(1, 'l'),
known(2, 'a'),
known(3, 'g'),
known(4, '{'),
0,
0,
known(-1, '}'),
0,
0
]
def decode(text, key):
k = len(key)
n = len(text)
l = len(alphabets)
return "".join([alphabets[(pos(text[i]) - key[i % k]) % l] for i in range(n)])
for a in range(len(alphabets)):
key[5] = a
print('.', end='')
sys.stdout.flush()
for b in range(len(alphabets)):
key[6] = b
for c in range(len(alphabets)):
key[8] = c
for d in range(len(alphabets)):
key[9] = d
res = decode(C, key)
m = md5(res.encode("ascii")).hexdigest()
if m == hash:
print(res)
#print(key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment