-
-
Save therealmik/2adbd9eb848d34886c48 to your computer and use it in GitHub Desktop.
DES(p,k) == ~DES(~p,~k)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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