注意:下面的代码是用python语言实现的
#导入和文件操作有关的模块
import os
#首先打开文件
f = open(r"D:\python\02\file3.txt")
neirong = f.read()
#显示原来文件中的内容
print("源文件中的内容:"+neirong)
newStr = ""
for string in neirong:
swaplocal = ord(string)
if swaplocal in range(65,91):
if swaplocal == 90:
char1 = chr(swaplocal-25)
newStr += char1
else:
char2 = chr(swaplocal+1)
newStr += char2
elif tempswaplocal in range(97,123):
if swaplocal == 122:
char3 = chr(swaplocal-25)
newStr += char3
else:
char4 = chr(swaplocal + 1)
newStr += char4
else:
newStr = newStr+string
f.close()
f2 = open(r"D:\python\02\file5.txt","w")
r=f2.write(newStr)
#加密后文件的内容
print("修改后文件中的内容:")
print(f2.write(newStr))
f2.close()