Keksike

Шифр для третьей лабы, придумал сам(mod 3, +5, +10, +15)

Mar 23rd, 2022
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. alf = {'а':1, 'б':2, 'в':3, 'г':4, 'д':5, 'е':6, 'ж':7, 'з':8, 'и':9, 'й':10, 'к':11, 'л':12, 'м':13, 'н':14, 'о':15, 'п':16, 'р':17, 'с':18, 'т':19, 'у':20, 'ф':21, 'х':22, 'ц':23, 'ч':24, 'ш':25, 'щ':26, 'ъ':27, 'ы':28, 'ь':29, 'э':30, 'ю':31, 'я':32, ',':33, '-':34, '!':35, '?':36, '.':37, ' ':38, '_':39}
  2.  
  3. def get_key(alf, value):
  4.   for k, v in alf.items():
  5.     if v == value:
  6.       return k
  7.  
  8. def index(list, alf):
  9.   index = alf.get(list[i])
  10. #  print(list[i], "- Буква,", index, "- Номер буквы")
  11.   return index
  12.  
  13. def correct(ind):
  14.   if ind < 33:
  15.     if (ind%3) == 0:
  16.       ind += 5
  17.       if ind > 32:
  18.         ind -= 32
  19.     elif (ind%3) == 1:
  20.       ind += 10
  21.       if ind > 32:
  22.         ind -= 32
  23.     elif (ind%3) == 2:  
  24.       ind += 15
  25.       if ind > 32:
  26.         ind -= 32
  27.   else:
  28.     ind = 39
  29.   return ind
  30.  
  31. message = input("Enter message:\n")
  32. list_message = []
  33.  
  34. list_cod = []
  35.  
  36. for c in message: # идем по строке
  37.     list_message.append(c) # добавляем буквы в список
  38. #print(list_message, "\n")
  39.  
  40. for i in range(len(list_message)):
  41.   index_s = index(list_message, alf)
  42.   index_m = correct(index_s)
  43. #  print(index_m, "- Номер буквы(", i, ") в конечном сообещении")
  44.  
  45.   list_cod.append(get_key(alf, index_m))
  46.   message_m = "".join(list_cod)
  47.  
  48. print(message, "- Начально сообщение")
  49. print(message_m, "- Зашифрованное сообщение")
Advertisement
Add Comment
Please, Sign In to add comment