Created
May 2, 2014 19:06
-
-
Save BillKeenan/01983ba08980b5774269 to your computer and use it in GitHub Desktop.
sameple
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
from Crypto.Cipher import AES | |
from Crypto import Random | |
import hashlib | |
import os | |
import math | |
import sys | |
import binascii | |
import string | |
def sxor(s1,s2): | |
return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2)) | |
def S1(y,x): | |
result = plainAES(y,x) | |
# then xor against y | |
message = sxor(result,binascii.a2b_hex(y)) | |
return message | |
def S2(x,y): | |
result = plainAES(x,x) | |
# then xor against y | |
message = sxor(result,binascii.a2b_hex(y)) | |
return message | |
def printBin(x): | |
for char in x: | |
sys.stdout.write(string.zfill(bin(ord(char))[2:], 8)) | |
def plainAES(y,x): | |
x = binascii.a2b_hex(x) | |
y = binascii.a2b_hex(y) | |
## uses the x for key AND message | |
cipher = AES.new(y, AES.MODE_ECB) | |
result = cipher.encrypt(x) | |
return result | |
def plainAESDecrypt(y,x): | |
x = binascii.a2b_hex(x) | |
y = binascii.a2b_hex(y) | |
## uses the x for key AND message | |
cipher = AES.new(y, AES.MODE_ECB) | |
result = cipher.decrypt(x) | |
return result | |
## solve for 1 | |
y1 = '00000000000000000000000000000000' | |
##OK solve for s2 | |
x2 = '00000000000000000000000000000001' | |
y2 = '00000000000000000000000000000011' | |
## solve the right | |
right = sxor(S1(y2,x2),binascii.a2b_hex(y1)) | |
print ('right:'+binascii.hexlify(right)) | |
## the left should be decrypt(y1,right) | |
x1 = binascii.hexlify(plainAESDecrypt(y1,binascii.hexlify(right))) | |
print ('these should match') | |
print binascii.hexlify(S1(y1,x1)) | |
print binascii.hexlify(S1(y2,x2)) | |
print ('x1:' + y1) | |
print ('y1:' + x1) | |
print ('x2:' + y2) | |
print ('y2:' + x2) | |
# solve for e(y,) | |
print ('################') | |
## so get the plain AES for x1 | |
aesX1 = plainAES(x1,x1) | |
print ('first AES') | |
print ( binascii.hexlify(aesX1)) | |
#so, this S2 should be equal to 0 | |
s2result = S2(x1,binascii.hexlify(aesX1)) | |
print ('result') | |
print binascii.hexlify(s2result) | |
x2 = '10000000000000000000000000000000' | |
## so get the plain AES for x1 | |
y2 = plainAES(x2,x2) | |
print ('first AES') | |
print ( binascii.hexlify(y2)) | |
#so, this S2 should be equal to 0 | |
s2result2 = S2(x2,binascii.hexlify(y2)) | |
print ('result') | |
print binascii.hexlify(s2result2) | |
print ('x1:'+ x1) | |
print ('y1:'+ binascii.hexlify(aesX1)) | |
print ('Result:'+binascii.hexlify(s2result)) | |
print ('x2:'+ x2) | |
print ('y2:'+ binascii.hexlify(y2)) | |
print ('Result:'+binascii.hexlify(s2result2)) | |
sys.exit(0) | |
y1 = '00000000000000000000000000000000' | |
result1 = S2(x1,y1) | |
printBin(result) | |
##so, whatever we pu | |
## Random Key | |
x2 = 'fffffff000000000000000000000ffff' | |
x = binascii.a2b_hex(x2) | |
# then xor against y | |
y2 = binascii.hexlify(sxor(result,result1)) | |
printBin(result1) | |
printBin(sxor(result,result1)) | |
printBin(result) | |
print ('creating s1 test') | |
collisionTEst = S2(x2,y2) | |
print ('results should match') | |
print binascii.hexlify(result1) | |
print binascii.hexlify(collisionTEst) | |
print ('x1:'+x1) | |
print ('y1:'+y1) | |
print ('x2:'+x2) | |
print ('y2:'+y2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment