AES加密,,[Python]代码fr


[Python]代码

from Crypto.Cipher import AESclass mycrypt():    def __init__(self,key):        self.key = key        self.mode = AES.MODE_CBC    def myencrypt(self,text):        cryptor = AES.new(key,self.mode)        length = 16        count = text.count('')        if count < length:            add = (length-count) + 1            text = text + (' ' * add)        elif count > length:            add = (length-(count % length)) + 1            text = text + (' ' * add)        self.ciphertext = cryptor.encrypt(text)        return self.ciphertext    def mydecrypt(self,text):        cryptor = AES.new(key,self.mode)        plain_text  = cryptor.decrypt(text)        return plain_texttext = "98789khjsajfilahfpoiwufipoasufipo"key = "9878*(&^^&)0LLIu(*&^))#$@!KJLKJj"en = mycrypt(key)entext = en.myencrypt(text)print entextdetext = en.mydecrypt(entext).rstrip()print detext

评论关闭