Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def __innernCBCtripleDES(self, data, key, iv, crypt = 'ENCRYPT'):
- result = b''
- iv1 = iv2 = iv3 = iv
- key1 = key[:8]
- key2 = key[8:16]
- if len(key) == 16:
- key3 = key1
- else:
- key3 = key[16:]
- print(len(data))
- for x in range(0, len(data), 8):
- if crypt == 'ENCRYPT':
- cipher = DES.new(key1, DES.MODE_CBC, iv1)
- block = cipher.encrypt(data[x:x+8])
- iv1 = block
- cipher = DES.new(key2, DES.MODE_CBC, iv2)
- block = cipher.decrypt(block)
- iv2 = block
- cipher = DES.new(key3, DES.MODE_CBC, iv3)
- block = cipher.encrypt(block)
- iv3 = block
- result += block
- else:
- cipher = DES.new(key3, DES.MODE_CBC, iv1)
- block = cipher.decrypt(data[x:x+8])
- iv1 = block
- cipher = DES.new(key2, DES.MODE_CBC, iv2)
- block = cipher.encrypt(block)
- iv2 = block
- cipher = DES.new(key1, DES.MODE_CBC, iv3)
- block = cipher.decrypt(block)
- iv3 = block
- result += block
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement