Python实现换位加密:四个字符为一组,实现1、2位交换,3、4位交换
def
trans(s
,t
):
result
=[]
temp
=[ s
[i
:i
+len(t
)] for i
in range(0,length
,len(t
))]
for item
in temp
:
newItem
=''
for i
in t
:
newItem
= newItem
+ item
[i
-1]
result
.append(newItem
)
return ''.join(result
)
f
= open('a.txt','r')
s
= f
.read()
length
= len(s
)
f
.close()
print(s
+'\n')
b
= trans(s
,(2,1,4,3))
f
= open('b.txt','w')
f
.write(b
)
f
.close()
print(b
+'\n')
转载请注明原文地址: https://win8.8miu.com/read-1452932.html