Advertisement
Tevronis

cezar

Feb 14th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from io import open
  3.  
  4. __author__ = 'entsmv'
  5.  
  6.  
  7. def obr(x):
  8.     for i in range(1000):
  9.         if (x * i) % m == 1:
  10.             return i
  11.  
  12.  
  13. def euclid(x, y):
  14.     while x != y:
  15.         if x > y:
  16.             x -= y
  17.         else:
  18.             y -= x
  19.     return True if x == 1 else False
  20.  
  21.  
  22. alph = u'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
  23. #alph = u'abcdefghijklmnopqrstuvwxyz '
  24. m = len(alph)
  25. alph2 = [u'' for i in range(m)]
  26.  
  27. k, n = 4, 7
  28. if not euclid(m, n):
  29.     print('ERROR')
  30.     exit()
  31.  
  32. for i in range(m):
  33.     alph2[i] = alph[(i * n + k) % m]
  34.  
  35. file = open('input.txt', encoding='utf-8')
  36. out_file = open('output.txt', 'w', encoding='utf-8')
  37.  
  38. for line in file:
  39.     for i in line:
  40.         try:
  41.             ind = alph.index(i)
  42.         except:
  43.             continue
  44.         out_file.write(alph2[ind])
  45.     out_file.write('\n'.decode('utf-8'))
  46.  
  47. out_file.close()
  48. out_file = open('output.txt', encoding='utf-8')
  49. out_file2 = open('output2.txt', 'w', encoding='utf-8')
  50. for line in out_file:
  51.     for i in line:
  52.         try:
  53.             ind = alph2.index(i)
  54.         except:
  55.             continue
  56.         r = (((ind - k + m) % m) * obr(n)) % m
  57.         out_file2.write(alph2[r])
  58.     out_file2.write('\n'.decode('utf-8'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement