# Coding=utf-8
From M2CRYPTO.EVP import Cipher
From M2crypto import m2
From m2crypto import util
Import Urllib
Import Sys
Import Base64
Import Binascii
Import Crypto
Import Crypto.random
Import Array
From Crypto.cipher import AES
ENCRYPT_OP = 1 # encryption operation
Decrypt_op = 0 # decryption operation
#print Crypto.Random.OSRNG.posix.new (). Read (Aes.block_size)
IV = ' 16 # initialization variable, useless for AES_128_ECB algorithm
Iv_arr=b ' \x01\x01\x0b\x05\x04\x0f\x07\x09\x17\x03\x01\x06\x08\x0c\x0d\x5b '
Iv=iv_arr
Private_key = ' Mymiyao ' # key
def Encrypt (data):
' Encrypt data using the AES_128_ECB algorithm '
cipher = cipher (ALG = ' AES_128_CBC ', key = Private_key, IV = IV, OP = encrypt_op)
BUF = cipher.update (data)
BUF = buf + cipher.final ()
del cipher
# transfer plaintext from byte to 16
Output = '
For I in BUF:
Output + + '%02x '% (ord (i))
Return output
def Decrypt (data):
' Decrypt data using the AES_128_ECB algorithm '
# Convert ciphertext from 16 to byte stream
data = UTIL.H2B (data)
cipher = cipher (ALG = ' AES_128_CBC ', key = Private_key, IV = IV, OP = decrypt_op)
BUF = cipher.update (data)
BUF = buf + cipher.final ()
del cipher
return BUF
data = Sys.argv[1]
data = urllib.unquote (data)
data = base64.decodestring (data)
data = Data.encode (' hex ')
Print Decrypt (data)
#encrypt_data = Encrypt (data)
#encrypt_data =data.decode (' hex ')
#encrypt_data =base64.encodestring (Encrypt_data)
#print Encrypt_data