Skip to content

Instantly share code, notes, and snippets.

@jepler
Created March 13, 2017 12:33
Show Gist options
  • Save jepler/96d1e779dc95b8941b208887e10a8084 to your computer and use it in GitHub Desktop.
Save jepler/96d1e779dc95b8941b208887e10a8084 to your computer and use it in GitHub Desktop.
import sha
import sys
f = open("/dev/urandom", "rb")
while 1:
sys.stderr.write(".")
message0 = f.read(256)
cs0 = sha.new(message0).digest()[:2]
flip_bit = 1 << (ord(f.read(1)) % 8)
flip_byte = ord(f.read(1))
message1 = message0[:flip_byte] + chr(ord(message0[flip_byte]) ^ flip_bit) + message0[flip_byte+1:]
cs1 = sha.new(message1).digest()[:2]
if cs0 == cs1:
print cs0.encode("hex"), flip_bit, flip_byte
print message0.encode("hex")
print message1.encode("hex")
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment