程序读取用户想要加密的文件:
with open(encryptSpecialFileName,mode= "r",encoding= "UTF-8") as myFile:
fileToSpecialEncrypt = myFile.read().splitlines()
然后程序设置加密消息的列表。
encryptedSpecialFile = []
for string in fileToSpecialEncrypt:
s1 = ""
for char in string:
(这里调用加密文件的函数)
encryptedSpecialChar = encryptSpecialCharacter(char, offset)
然后将加密的字符添加到列表中。
s1 = s1 + encryptedSpecialChar
encryptedSpecialFile.append(s1)
如何将此字符串拆分为五个块以使解密更加困难?
答案 0 :(得分:1)
要将加密的字符串拆分为五个一组,我们可能会将前5个字符收集到一个字符串中,然后将该字符串附加到列表中。然后我们重复该过程,直到整个加密字符串用完为止。
encryptedString = "Thisistheencryptedtexttobesplitintogroupsoffive."
encryptedChunks = []
chunk = ""
for ch in encryptedString:
if len(chunk)==5:
encryptedChunks.append(chunk)
chunk = ch
else:
chunk += ch
encryptedChunks.append(chunk)
print encryptedChunks
此处,变量encryptedString
包含从函数encryptSpecialCharacter(char, offset)
返回的字符串。