This need to use Crypto.cipher this plug-in to achieve, after the reference only need to write the following code to
1 fromCrypto.cipherImportDES2 3 classMydescrypt:4 5Key = Chr (one) +CHR (one) +chr (one) +chr (one) +chr (one) +chr (one) +chr (one) +CHR (11)6IV = CHR (+CHR) +CHR (22) +CHR (+) +CHR (+CHR) +CHR (+) +CHR)7 8 def __init__(self,key="', iv="'):9 ifLen (key) >0:TenSelf.key =Key One ifLen (iv) >0: ASELF.IV =IV - - defEcrypt (self,ecrypttext): the Try: -Cipherx =des.new (Self.key, DES. MODE_CBC, SELF.IV) -Pad = 8-len (ecrypttext)% 8 -Padstr ="" + forIinchRange (PAD): -Padstr = Padstr +chr (PAD) +Ecrypttext = Ecrypttext +Padstr Ax =Cipherx.encrypt (Ecrypttext) at returnX.encode ('Hex_codec'). Upper () - except: - return "" - - - defDecrypt (self,decrypttext): in Try: - toCipherx =des.new (Self.key, DES. MODE_CBC, SELF.IV) +str = Decrypttext.decode ('Hex_codec') -y =cipherx.decrypt (str) the returnY[0:ord (Y[len (y)-1]) *-1] * except: $ return ""
Python DES Encryption and decryption is the very fast way that everyone wants.