Last active
September 28, 2023 09:57
-
-
Save etemesi254/50b7e4340c3f47d1d77a4ac56fdd83a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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