InnaSibirova

Шифр Виженера

Dec 1st, 2018
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def ok(x):
  2. if 65 <= x <= 90:
  3. x = x - 65
  4. return(x)
  5. elif 97<= x <=122:
  6. x = x - 97
  7. return(x)
  8. i = 0
  9. sh = '\0'
  10. while True:
  11. print(' шифратор-1\n дешифратор-2')
  12. q=int(input('commad'))
  13. if q==1:
  14. text = input('text')
  15. key = input('key')
  16. while i < len(text):
  17. a = ord(text[i])
  18. k = ord(key[i%len(key)])
  19. if 65 <= a <= 90:
  20. a = a - 65 + ok(k)
  21. if a>25:
  22. a = a - 26
  23. a = a + 65
  24. elif 97<= a <=122:
  25. a = a - 97 + ok(k)
  26. if a>25:
  27. a = a - 26
  28. a = a + 97
  29. sh = sh + chr(a)
  30. i+=1
  31. print ('\n \n' + sh)
  32. elif q==2:
  33. text = input('text')
  34. key = input('key')
  35. while i < len(text):
  36. a = ord(text[i])
  37. k = ord(key[i%len(key)])
  38. if 65 <= a <= 90:
  39. a = a - 65 - ok(k)
  40. if 0>a:
  41. a = a + 26
  42. a = a + 65
  43. elif 97<= a <=122:
  44. a = a - 97 - ok(k)
  45. if 0>a:
  46. a = a + 26
  47. a = a + 97
  48. sh = sh + chr(a)
  49. i+=1
  50. print ('\n \n' + sh)
  51. else:
  52. print('this command not exist')
RAW Paste Data