Skip to content

Instantly share code, notes, and snippets.

@jhs7jhs

jhs7jhs/solver.py Secret

Created Nov 12, 2020
Embed
What would you like to do?
Solver for KCD
#!/usr/bin/env python3
def decrypt(inp, key):
out = ""
for c in inp:
if ord('a') <= ord(c) <= ord('z'):
out += chr(ord('a') + (ord(c) - ord('a') - key) % 26)
elif ord('A') <= ord(c) <= ord('Z'):
out += chr(ord('A') + (ord(c) - ord('A') - key) % 26)
elif ord('가') <= ord(c) <= ord('힣'):
out += chr(ord('가') + (ord(c) - ord('가') - key) % 11172)
else:
out += c
return out
inp = "Zglem{Bgb_뾢_rfGli_궖묦_뿶숊_CYQW?_뺊묦_Rfgq_gq_뿶-쉂.}"
# key % 26 == 24
# for key in range(26):
# print(key, decrypt(inp, key))
from jamo import j2hcj, h2j
possible_outputs = []
for key in range(24, 11172, 26):
hcj = j2hcj(h2j(decrypt(inp, key)))
if 'ㅇ' in hcj and 'ㅈ' in hcj:
possible_outputs.append((len(hcj), decrypt(inp, key)))
possible_outputs.sort()
for v in possible_outputs:
print(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.