【python初学】仿射加密的简单实现

初学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

你可能感兴趣的:(python初学)