使用内置pow函数,该题可这样解:
with open('encrypted.txt', 'w', encoding='utf-8') as f0:
en = []
for x in 'this is a message':
en.append(chr(pow(ord(x),19,221)))
enc = ''.join(en)
f0.write(enc)
with open('encrypted.txt','r',encoding='utf-8') as f,open('decrypted.txt','w',encoding='utf-8') as f1:
#decrypted:this is a message
de=[]
for c in f.read().strip():
de.append(chr(pow(ord(c),91,221)))
dec=''.join(de)
f1.write(dec)
print(dec)
如对你有帮助,请采纳。点击我回答右上角【采纳】按钮。