Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. import string
  2. from string import punctuation
  3. alpha = 'абвгдежзийклмнопрстуфхцчшщъыьэюя' +'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ' +'., :;-()!?*"'
  4. a = int(input("1-шифровать/2-расшифровать"))
  5. res = ''
  6. if a == 1:
  7.         s = input("Введите текст для зашифрования:").rstrip()
  8.         n = int(input("Ключ:"))
  9.         for c in s:
  10.             if c.isalpha():
  11.                 res += alpha[(alpha.index(c) + n) % len(alpha)]
  12.                 for number in alpha:
  13.                      number=alpha.index(c)
  14.                      print(number)
  15.             elif c in string.punctuation:
  16.                 res += alpha[(alpha.index(c) + n) % len(alpha)]
  17.                 for number in alpha:
  18.                      number=alpha.index(c)
  19.                      print(number)
  20.             else:
  21.                 res += c
  22.         print('Result: ' + res)
  23. elif a == 2:
  24.         s = input("Введите текст для расшифрования:").rstrip()
  25.         n = int(input("Ключ:"))
  26.         for c in s:
  27.             if c.isalpha():
  28.                 res += alpha[(alpha.index(c) - n) % len(alpha)]
  29.             elif c in string.punctuation:
  30.                 res += alpha[(alpha.index(c) - n) % len(alpha)]
  31.             else:
  32.                 res += c
  33.         print('Result: ' + res)
  34. else: print('Ашипка')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement