Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (27 sloc) 956 Bytes
import sys
import argparse
from Crypto.Cipher import AES
from bitstring import BitStream
parser = argparse.ArgumentParser(description='Read from stdin and decrypt each line with AES key (from hex encoding)')
parser.add_argument('--key', help='file containing the AES encryption key', required=True)
args = parser.parse_args()
with open (args.key, "rb") as f:
key =
for line in sys.stdin:
line = line.replace('\r','').replace('\n', '')
if len(line) == 0:
line = BitStream(hex=line)
iv = line[0:128]
data = line[128:]
#print("iv=%s, data=%s" % (iv.hex, data.hex))
crypter =, AES.MODE_CBC, iv.bytes)
output = crypter.decrypt(data.bytes).decode('ascii').replace('\00', '')
sys.stdout.write(output + "\r\n")
except ValueError as e:
print("ValueError: %s" % e, file=sys.stderr)
print("ERROR %s, LINE=%s" % (sys.exc_info()[0], line), file=sys.stderr)