Python DES encryption and decryption is what we call the very fast method, pythondes
This is implemented using the Crypto. Cipher plug-in. After referencing it, you only need to write the following code:
1 from Crypto.Cipher import DES 2 3 class MyDESCrypt: 4 5 key = chr(11)+chr(11)+chr(11)+chr(11)+chr(11)+chr(11)+chr(11)+chr(11) 6 iv = chr(22)+chr(22)+chr(22)+chr(22)+chr(22)+chr(22)+chr(22)+chr(22) 7 8 def __init__(self,key='',iv=''): 9 if len(key)> 0:10 self.key = key11 if len(iv)>0 :12 self.iv = iv13 14 def ecrypt(self,ecryptText):15 try:16 cipherX = DES.new(self.key, DES.MODE_CBC, self.iv)17 pad = 8 - len(ecryptText) % 818 padStr = ""19 for i in range(pad):20 padStr = padStr + chr(pad)21 ecryptText = ecryptText + padStr22 x = cipherX.encrypt(ecryptText)23 return x.encode('hex_codec').upper()24 except:25 return ""26 27 28 def decrypt(self,decryptText):29 try:30 31 cipherX = DES.new(self.key, DES.MODE_CBC, self.iv)32 str = decryptText.decode('hex_codec')33 y = cipherX.decrypt(str)34 return y[0:ord(y[len(y)-1])*-1]35 except:36 return ""