Skip to content

Instantly share code, notes, and snippets.

@ronaldstoner
Created August 11, 2017 14:18
Show Gist options
  • Save ronaldstoner/24f234a9b2f896e645ae885dd818ee95 to your computer and use it in GitHub Desktop.
Save ronaldstoner/24f234a9b2f896e645ae885dd818ee95 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