Skip to content

Instantly share code, notes, and snippets.

@etemesi254
Last active September 28, 2023 09:57
Show Gist options
  • Save etemesi254/50b7e4340c3f47d1d77a4ac56fdd83a3 to your computer and use it in GitHub Desktop.
Save etemesi254/50b7e4340c3f47d1d77a4ac56fdd83a3 to your computer and use it in GitHub Desktop.
plain_text = "wearediscoveredsaveyourself"
cipher_text = "ZICVTWQNGRZGVTWAVZHCQYGLMGJ".lower()
a_char = ord('a')
def one_mapping(c: str, d: str):
for (a, b) in zip(c, d):
if a > b:
# it overflowed(we reached z and went to a), so go from end to determine
# start
diff = 26 - abs(ord(b) - ord(a))
print(chr(diff + a_char), end="")
else:
# key didn't overflow(we didn't cross z->a), so it is just the
# difference of two letters
diff = abs(ord(b) - ord(a))
print(chr(diff + a_char), end="")
one_mapping(plain_text, cipher_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment