Skip to content

Instantly share code, notes, and snippets.

@dmb2
Created July 3, 2015 15:29
Show Gist options
  • Save dmb2/52a560ccfa2f2d790987 to your computer and use it in GitHub Desktop.
Save dmb2/52a560ccfa2f2d790987 to your computer and use it in GitHub Desktop.
def challenge17
server = CBCPaddingServer.new
iv,session_cookie = server.get_session_cookie()
block_size=16
puts session_cookie.blocks(block_size).length
blocks=session_cookie.blocks(block_size)
blocks=[iv]+blocks
decoded_byte_string=[]
1.upto(blocks.length-1) do |bi|
decoded_bytes=[]
block=blocks[-bi-1]
target_block=blocks[-bi]
1.upto(block_size) do |pad_byte|
256.times do |byte|
if byte == pad_byte
next
end
decoded_bytes[pad_byte-1]=byte
edited_block=create_edit_text(block,decoded_bytes,pad_byte)
if server.valid_decrypt(edited_block+target_block,iv)
break
end
end
end
decoded_byte_string+=decoded_bytes
end
puts decoded_byte_string.pack("C*").reverse.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment