Skip to content

Instantly share code, notes, and snippets.

@macostag
Created January 20, 2018 22:45
Show Gist options
  • Save macostag/98f370fbf16b473cd78cacd6893c8270 to your computer and use it in GitHub Desktop.
Save macostag/98f370fbf16b473cd78cacd6893c8270 to your computer and use it in GitHub Desktop.
Encrypt hex strings using 3DES (ECB mode).
import binascii
import random
import hashlib
import base64
from pyDes import *
def encrypt3DES(skey,sdata):
key = binascii.unhexlify(skey)
data = binascii.unhexlify(sdata)
key3DES = triple_des(key, ECB, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_NORMAL)
encrypted = key3DES.encrypt(data)
return encrypted
encryptionKey = INSERT ENCRYPTION KEY
print "Key (HEX Value):: "
print encryptionKey.upper()
inputData = INSERT INPUT DATA
print "Input Data (HEX Value):: "
print inputData.upper()
print ""
outputData = encrypt3DES(encryptionKey,inputData)
print "Output Data (HEX Value):: "
print str(binascii.hexlify(outputData)).upper()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment