Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. def __innernCBCtripleDES(self, data, key, iv, crypt = 'ENCRYPT'):
  2.             result = b''
  3.             iv1 = iv2 = iv3 = iv
  4.             key1 = key[:8]
  5.             key2 = key[8:16]
  6.             if len(key) == 16:
  7.                 key3 = key1
  8.             else:
  9.                 key3 = key[16:]
  10.             print(len(data))
  11.             for x in range(0, len(data), 8):
  12.                 if crypt == 'ENCRYPT':
  13.                     cipher = DES.new(key1, DES.MODE_CBC, iv1)
  14.                     block = cipher.encrypt(data[x:x+8])
  15.                     iv1 = block
  16.                     cipher = DES.new(key2, DES.MODE_CBC, iv2)
  17.                     block = cipher.decrypt(block)
  18.                     iv2 = block
  19.                     cipher = DES.new(key3, DES.MODE_CBC, iv3)
  20.                     block = cipher.encrypt(block)
  21.                     iv3 = block
  22.                     result += block
  23.                 else:
  24.                     cipher = DES.new(key3, DES.MODE_CBC, iv1)
  25.                     block = cipher.decrypt(data[x:x+8])
  26.                     iv1 = block
  27.                     cipher = DES.new(key2, DES.MODE_CBC, iv2)
  28.                     block = cipher.encrypt(block)
  29.                     iv2 = block
  30.                     cipher = DES.new(key1, DES.MODE_CBC, iv3)
  31.                     block = cipher.decrypt(block)
  32.                     iv3 = block
  33.                     result += block
  34.             return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement