Skip to content

Instantly share code, notes, and snippets.

@jlawhon
Forked from ronaldstoner/ciphertext.py
Created September 30, 2018 07:40
Show Gist options
  • Save jlawhon/0da2cd3ed5af9a5cdc7cd97b998eb90c to your computer and use it in GitHub Desktop.
Save jlawhon/0da2cd3ed5af9a5cdc7cd97b998eb90c to your computer and use it in GitHub Desktop.
ciphertext.py
# ARCYBER cipher text generator
# Modified from existing code on the internet
def subchar(a, b):
return (((ord(b)-97) - (ord(a)-97)) % 26) + 97
def getkey(question, answer):
assert len(question) == len(answer), 'Length mismatch'
q = question.lower()
a = answer.lower()
result = []
for i in range(len(question)):
if question[i] == ' ':
char = ' '
else:
char = chr(subchar(q[i], a[i]))
# if uppercase
if ord(question[i]) < 97:
char = char.upper()
result.append(char)
return ''.join(result)
one = 'rstoner leet hax omg'
two = 'Ccoheal ieuw qwu tcb'
getkey(one, two)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment