Last active
April 16, 2020 16:10
-
-
Save kurzweil777/3a711ff89818679bfa1032556621a55d to your computer and use it in GitHub Desktop.
Functions
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
letters = "А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я" | |
divided_letters = letters.split() | |
def encrypt(s, k): | |
mod_letters = [] | |
for w in s.upper(): | |
if w in divided_letters: | |
index = divided_letters.index(w) + k | |
if index > len(divided_letters) or index < 0: | |
index = index % len(divided_letters) | |
else: | |
pass | |
mod_letters.append(divided_letters[index]) | |
normal_letters = ''.join(mod_letters) | |
else: | |
mod_letters.append(w) | |
normal_letters = ''.join(mod_letters) | |
return str(normal_letters) | |
message = "Привет world!" | |
encrypted_message = encrypt(message, 55) | |
decrypted_message = encrypt(encrypted_message, -55) | |
print(encrypted_message) | |
print(decrypted_message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment