Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from io import open
- __author__ = 'entsmv'
- def obr(x):
- for i in range(1000):
- if (x * i) % m == 1:
- return i
- def euclid(x, y):
- while x != y:
- if x > y:
- x -= y
- else:
- y -= x
- return True if x == 1 else False
- alph = u'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
- #alph = u'abcdefghijklmnopqrstuvwxyz '
- m = len(alph)
- alph2 = [u'' for i in range(m)]
- k, n = 4, 7
- if not euclid(m, n):
- print('ERROR')
- exit()
- for i in range(m):
- alph2[i] = alph[(i * n + k) % m]
- file = open('input.txt', encoding='utf-8')
- out_file = open('output.txt', 'w', encoding='utf-8')
- for line in file:
- for i in line:
- try:
- ind = alph.index(i)
- except:
- continue
- out_file.write(alph2[ind])
- out_file.write('\n'.decode('utf-8'))
- out_file.close()
- out_file = open('output.txt', encoding='utf-8')
- out_file2 = open('output2.txt', 'w', encoding='utf-8')
- for line in out_file:
- for i in line:
- try:
- ind = alph2.index(i)
- except:
- continue
- r = (((ind - k + m) % m) * obr(n)) % m
- out_file2.write(alph2[r])
- out_file2.write('\n'.decode('utf-8'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement