在密文转换中添加空格

时间:2019-03-10 20:10:22

标签: python python-3.x encryption

我正在尝试将纯文本转换为密文:

  

plaintext ='保卫城堡的东墙'

     

密文:'efgfoe uif fbtu xbmm pg uif dbtumf'

p = plaintext.split(' ')
for i in p:
    i2=[i]
    for word in i2:
        for letter in word:
            inc=ord(letter)+1
            print(chr(inc),end='')

我得到的解决方案是:

efgfoeuiffbtuxbmmpguifdbtumf

如何将相关空格包括为纯文本?

就像:'efgfoe uif fbtu xbmm pg uif dbtumf'

1 个答案:

答案 0 :(得分:0)

这应该做

plaintext = 'defend the east wall of the castle'
p = plaintext.split(' ')
wholecipher=[]
for word in p:
    word_cipher=''
    for letter in word:
        inc=ord(letter)+1
        word_cipher += chr(inc)
    wholecipher.append(word_cipher)

print(' '.join(wholecipher))