Created
August 28, 2020 16:12
-
-
Save DNDK/3aaf1ffc9614771e2fdeda6e965c029b to your computer and use it in GitHub Desktop.
Caesar encoding
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
alph = [ | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", | |
"abcdefghijklmopqrstuvwxyz", | |
] | |
text = input("Enter the text\n>>") | |
shift = input("Enter the shift\n>>") | |
try: | |
shift = int(shift) | |
except ValueError: | |
print("Shift must be a number!") | |
else: | |
encoded = "" | |
for i in text: | |
if i.isalpha(): | |
if i.isupper(): | |
index = alph[0].index(i) | |
index +=shift | |
while index>26: | |
index -= 26 | |
encoded += alph[0][index] | |
else: | |
index = alph[1].index(i) | |
index += shift | |
while index>26: | |
index -= 26 | |
encoded += alph[1][index] | |
else: | |
encoded+=i | |
print(encoded) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment