Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def encrypt(a, b, c):
- alfa = 'abcdefghijklmnopqrstuvwxyz'
- betta = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
- gamma = '' '.,:;"`\|/(){}[]!?@#$&№%^+-=_*'
- res = []
- if b == 0:
- for i in c:
- if i.isalpha() == False:
- res.append(gamma[(gamma.find(i)+a)%len(gamma)])
- else:
- res.append(alfa[(alfa.find(i)+a)%len(alfa)])
- else:
- for i in c:
- if i.isalpha() == False:
- res.append(gamma[(gamma.find(i)+a)%len(gamma)])
- else:
- res.append(betta[(betta.find(i)+a)%len(betta)])
- return res
- def decrypt(a, b, c):
- alfa = 'abcdefghijklmnopqrstuvwxyz'
- betta = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
- gamma = '' '.,:;"`\|/(){}[]!?@#$&№%^+-=_*'
- res = []
- if b == 0:
- for i in c:
- if i.isalpha() == False:
- res.append(gamma[(gamma.find(i)-a)%len(gamma)])
- else:
- res.append(alfa[(alfa.find(i)-a)%len(alfa)])
- else:
- for i in c:
- if i.isalpha() == False:
- res.append(gamma[(gamma.find(i)-a)%len(gamma)])
- else:
- res.append(betta[(betta.find(i)-a)%len(betta)])
- return res
- res_shi = []
- res_des = []
- print("Введите, на какое количество символов вы хотите сделать сдвиг по алфавиту: ")
- n=int(input())
- print("На каком языке будет ваше предложение?(рус/eng)")
- m=input().strip()
- if m == "рус":
- m = 1
- else:
- m = 0
- print("Введите ваше предложение предложение")
- text = input()
- words_in_text= text.split()
- for i in range(len(words_in_text)):
- res_shi.append(''.join(encrypt(n, m, words_in_text[i])))
- print("Зашифрованное предложение:",(' '.join(res_shi)))
- for i in range(len(res_shi)):
- res_des.append(''.join(decrypt(n, m, res_shi[i])))
- print("Расшифрованное предложение:",(' '.join(res_des)))
Add Comment
Please, Sign In to add comment