Keksike

ИБ 1 лаба

Mar 8th, 2021 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. def encrypt(a, b, c):
  2.   alfa = 'abcdefghijklmnopqrstuvwxyz'
  3.   betta = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
  4.   gamma = '' '.,:;"`\|/(){}[]!?@#$&№%^+-=_*'
  5.   res = []
  6.   if b == 0:
  7.     for i in c:
  8.       if i.isalpha() == False:
  9.         res.append(gamma[(gamma.find(i)+a)%len(gamma)])
  10.       else:
  11.         res.append(alfa[(alfa.find(i)+a)%len(alfa)])
  12.   else:
  13.     for i in c:
  14.       if i.isalpha() == False:
  15.         res.append(gamma[(gamma.find(i)+a)%len(gamma)])
  16.       else:
  17.         res.append(betta[(betta.find(i)+a)%len(betta)])
  18.   return res
  19.  
  20. def decrypt(a, b, c):
  21.   alfa = 'abcdefghijklmnopqrstuvwxyz'
  22.   betta = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
  23.   gamma = '' '.,:;"`\|/(){}[]!?@#$&№%^+-=_*'
  24.   res = []
  25.   if b == 0:
  26.     for i in c:
  27.       if i.isalpha() == False:
  28.         res.append(gamma[(gamma.find(i)-a)%len(gamma)])
  29.       else:
  30.         res.append(alfa[(alfa.find(i)-a)%len(alfa)])
  31.   else:
  32.     for i in c:
  33.       if i.isalpha() == False:
  34.         res.append(gamma[(gamma.find(i)-a)%len(gamma)])
  35.       else:
  36.         res.append(betta[(betta.find(i)-a)%len(betta)])
  37.   return res
  38.  
  39. res_shi = []
  40. res_des = []
  41.  
  42. print("Введите, на какое количество символов вы хотите сделать сдвиг по алфавиту: ")
  43. n=int(input())
  44.  
  45. print("На каком языке будет ваше предложение?(рус/eng)")
  46. m=input().strip()
  47. if m == "рус":
  48.   m = 1
  49. else:
  50.   m = 0
  51.  
  52. print("Введите ваше предложение предложение")
  53. text = input()
  54. words_in_text= text.split()
  55.  
  56. for i in range(len(words_in_text)):
  57.   res_shi.append(''.join(encrypt(n, m, words_in_text[i])))
  58. print("Зашифрованное предложение:",(' '.join(res_shi)))  
  59.  
  60. for i in range(len(res_shi)):
  61.   res_des.append(''.join(decrypt(n, m, res_shi[i])))
  62. print("Расшифрованное предложение:",(' '.join(res_des)))
Add Comment
Please, Sign In to add comment