Skip to content

Instantly share code, notes, and snippets.

@dmb2
Created June 30, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmb2/172602d372050ea8d9fd to your computer and use it in GitHub Desktop.
Save dmb2/172602d372050ea8d9fd to your computer and use it in GitHub Desktop.
# Cipher text is a bytestring
# bi is the block index, or which block to edit. Flipping a bit in this block will result in a one bit edit in the bi+1 plaintext block
# i is the targeted bit's index
# z is the array of decoded bytes.
# The idea here is to target bit i, but also flip the bits of previously discovered bytes.
def flip_bit(cipher_text,bi,i,z)
bsize=16
i.times do |j|
tb=(z[j-1]==nil) ? 0 : z[j-1]
cb=cipher_text.bytes()[bi*bsize-j-1]
cipher_text[bi*bsize-j-1]=(cb^tb^i).chr
end
return cipher_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment