Skip to content

Instantly share code, notes, and snippets.

@aburan28
Forked from therealmik/desnot.py
Last active March 10, 2017 19:50
Show Gist options
  • Save aburan28/4726bbcb58cda3cb6f0c to your computer and use it in GitHub Desktop.
Save aburan28/4726bbcb58cda3cb6f0c to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
from Crypto.Cipher import DES
import os
from binascii import hexlify
def bitwise_not(buf):
return bytes([ (~b) & 0xff for b in buf ])
def print_hex(name, value):
value = str(hexlify(value), "utf-8")
print("{0:s}\t{1:s}".format(name, value))
key = os.urandom(8)
plain = os.urandom(8)
notkey = bitwise_not(key)
notplain = bitwise_not(plain)
cipher = DES.new(key, DES.MODE_ECB).encrypt(plain)
notcipher = DES.new(notkey, DES.MODE_ECB).encrypt(notplain)
print_hex(" Ciphertext", cipher)
print_hex("~Ciphertext", notcipher)
print_hex("|Ciphertext", bytes([ cipher[i] | notcipher[i] for i in range(8)]))
print_hex("&Ciphertext", bytes([ cipher[i] & notcipher[i] for i in range(8)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment