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

时间:2014-10-08 23:35:19

标签: 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 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)

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

bin()将为您提供最短的代表性。这将以各种方式阻止你。

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