【python初學】仿射加密的簡單實現
阿新 • • 發佈:2019-01-23
初學python,拿最近學的Affine Cipher實現個小程式……應該是各種不完善……
求輕噴b( ̄▽ ̄)d……
def affine(a, b):
try:
f = open(r'f:/affine.txt', 'r')
except IOError, e:
print 'Cannot open ', e
out = open('f:/out.txt', 'w')
for line in f.readline():
for word in line:
if word != ' ' :
cipher = ((ord(word) - ord('a')) * a + b) % 26
out.write(str(chr(cipher + ord('a'))))
else:
out.write(' ')
f.close()
out.close()
return