Skip to content

Instantly share code, notes, and snippets.

@numinit
Last active February 24, 2017 04:28
Show Gist options
  • Save numinit/fdd204b0214805832fcae8d3a2ac44cd to your computer and use it in GitHub Desktop.
Save numinit/fdd204b0214805832fcae8d3a2ac44cd to your computer and use it in GitHub Desktop.
Usage: echo -n text_to_append | ruby shattered_length_extension.rb
#!/usr/bin/env ruby
# output format:
# => collided sha1
# => message 1 base64
# => message 2 base64
require 'base64'
require 'digest/sha1'
p1 = Base64.decode64(<<EOF)
JVBERi0xLjMKJeLjz9MKCgoxIDAgb2JqCjw8L1dpZHRoIDIgMCBSL0hlaWdodCAzIDAgUi9UeXBl
IDQgMCBSL1N1YnR5cGUgNSAwIFIvRmlsdGVyIDYgMCBSL0NvbG9yU3BhY2UgNyAwIFIvTGVuZ3Ro
IDggMCBSL0JpdHNQZXJDb21wb25lbnQgOD4+CnN0cmVhbQr/2P/+ACRTSEEtMSBpcyBkZWFkISEh
ISGFL+wJIzl1nDmxocY8TJfh//4Bc0bckWa2fhGPApq2IbJWD/nKZ8yox/hbqEx5AwwrPeIY+G2z
qQkB1d9FwU8m/t+z3DjpasIv571yjw5FvOBG0jxXD+sUE5i7VS71oKgr4zH+pIA3uLXXHw4zLt+T
rDUA603cDezBqGR5DHgsdiFWYN0wl5HQa9CvP5jNpLxGKbE=
EOF
p2 = Base64.decode64(<<EOF)
JVBERi0xLjMKJeLjz9MKCgoxIDAgb2JqCjw8L1dpZHRoIDIgMCBSL0hlaWdodCAzIDAgUi9UeXBl
IDQgMCBSL1N1YnR5cGUgNSAwIFIvRmlsdGVyIDYgMCBSL0NvbG9yU3BhY2UgNyAwIFIvTGVuZ3Ro
IDggMCBSL0JpdHNQZXJDb21wb25lbnQgOD4+CnN0cmVhbQr/2P/+ACRTSEEtMSBpcyBkZWFkISEh
ISGFL+wJIzl1nDmxocY8TJfh//4Bf0bck6a2fgE7ApqqHbJWC0XKZ9aIx/hLjEx5H+ArPfYU+G2x
aQkBxWtFwVMK/t+3YDjpcnIv561yjw5JBOBGwjBXD+nUE5ir4S71vJQr4zVCpIAtmLXXDyozLsN/
rDUU503cDyzBqHTNDHgwWiFWZGEwl4lga9C/P5jNqARGKaE=
EOF
extension = STDIN.read
m1 = p1 + extension
m2 = p2 + extension
m1_sha = Digest::SHA1.hexdigest(m1)
m2_sha = Digest::SHA1.hexdigest(m2)
if m1_sha == m2_sha and m1 != m2
STDOUT.puts m1_sha
STDOUT.puts Base64.strict_encode64(m1)
STDOUT.puts Base64.strict_encode64(m2)
else
raise "failed attempt at length extension"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment