Vermilliest

crossoverCode

Nov 28th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. import random
  2. import math
  3.  
  4.  
  5. def swap(source: list, index1: int, index2: int):
  6.     source[index1], source[index2] = source[index2], source[index1]
  7.     return source
  8.  
  9.  
  10. def shuffle(source: list, key: any):
  11.     random.seed(key)
  12.     for index1 in range(len(source)):
  13.         index2 = int(math.floor(random.random() * len(source)))
  14.         swap(source, index1, index2)
  15.     return source
  16.  
  17.  
  18. def crossoverCode(source: str, key: any):
  19.     chars = []
  20.     chars.extend(source)
  21.     shuffle(chars, key)
  22.     return ''.join(chars)
  23.  
  24.  
  25. def main():
  26.     print("Введите шифруемое сообщение:")
  27.     source: str = input()
  28.     print("Введите ключ:")
  29.     key: str = input()
  30.     print("Зашифрованное сообщение:", crossoverCode(source, key))
  31.     return True
  32.  
  33.  
  34. main()
Advertisement
Add Comment
Please, Sign In to add comment