Encryption Python中使用循环移位进行位移位加密和解密

Encryption Python中使用循环移位进行位移位加密和解密,encryption,python-3.4,Encryption,Python 3.4,编辑:我想出来了。这是我使用的代码 def bitshiftEncrypt(word): newWord = "" for i in word: shift = '{:07b}'.format(ord(i)+1) newShift = shift[1:] newShift += shift[0] newWord += chr(int(newShift,2)) print(newWord) def bitsh

编辑:我想出来了。这是我使用的代码

def bitshiftEncrypt(word):
    newWord = ""
    for i in word:
        shift = '{:07b}'.format(ord(i)+1)
        newShift = shift[1:]
        newShift += shift[0]
        newWord += chr(int(newShift,2))
    print(newWord)

def bitshiftDecrypt(word):
    newWord = ""
    for i in word:
        shift = '{:07b}'.format(ord(i))
        newShift = shift[len(str(shift))-1]
        newShift += shift[:-1:1]
        newWord += str(chr(int(newShift,2)-1))
    print(newWord)
谢谢你的帮助

bin()
将为您提供尽可能短的表示形式。这会以各种方式把你搞砸

3>> bin(3)
'0b11'
3>> '{:07b}'.format(3)
'0000011'

我很困惑。我使用bin()的方式[2::]切断了二进制文件的0b,因此我可以对其进行循环移位。这不是最好的路线吗?0b100001 0b1111010这可能是个问题:p我忽略了这一点。让我再看看我的代码。所以,当我解密它时,它的移位是错误的,因为有错误的位数。