Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- from string import punctuation
- alpha = 'абвгдежзийклмнопрстуфхцчшщъыьэюя' +'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ' +'., :;-()!?*"'
- a = int(input("1-шифровать/2-расшифровать"))
- res = ''
- if a == 1:
- s = input("Введите текст для зашифрования:").rstrip()
- n = int(input("Ключ:"))
- for c in s:
- if c.isalpha():
- res += alpha[(alpha.index(c) + n) % len(alpha)]
- for number in alpha:
- number=alpha.index(c)
- print(number)
- elif c in string.punctuation:
- res += alpha[(alpha.index(c) + n) % len(alpha)]
- for number in alpha:
- number=alpha.index(c)
- print(number)
- else:
- res += c
- print('Result: ' + res)
- elif a == 2:
- s = input("Введите текст для расшифрования:").rstrip()
- n = int(input("Ключ:"))
- for c in s:
- if c.isalpha():
- res += alpha[(alpha.index(c) - n) % len(alpha)]
- elif c in string.punctuation:
- res += alpha[(alpha.index(c) - n) % len(alpha)]
- else:
- res += c
- print('Result: ' + res)
- else: print('Ашипка')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement