Skip to content

Instantly share code, notes, and snippets.

@ficapy
Created April 20, 2016 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ficapy/2867e346436bcdc372b5ec27170fda24 to your computer and use it in GitHub Desktop.
Save ficapy/2867e346436bcdc372b5ec27170fda24 to your computer and use it in GitHub Desktop.
3DES双倍长加密
from Crypto.Cipher import DES3
import binascii
# 3DES加密32位ASCII字符串得到32位ASCII字符串
# 密匙长度16bytes
# 3DES密文长度于明文长度相符,所以要加密得到32位明文中间有16进制转换('1F'→→→'\x1f')
# 加密前2个ASCII字符转换成1bytes(限制了只能是0-F)
def des3(key, msg):
cipher = DES3.new(binascii.unhexlify(key), DES3.MODE_ECB)
ret = cipher.encrypt(binascii.unhexlify(msg))
return ''.join(i.upper() for i in binascii.hexlify(ret))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment