Paste: MD5game
Author: | _martind |
Mode: | factor |
Date: | Thu, 7 May 2009 15:52:19 |
Plain Text |
USING: byte-arrays checksums checksums.md5 io kernel lcs
math namespaces prettyprint random sequences syntax ;
IN: md5game
CONSTANT: buff_size 16
SYMBOL: lcs-so-far
: print-solutions* ( original md5 -- )
[ hex-string ] bi@
[ "Original: " write print ] dip
"MD5: " write print flush ;
: print-solutions ( original md5 -- original md5 )
2dup print-solutions* ;
: is-a-record? ( original md5 -- subseq ? )
lcs dup length lcs-so-far get > ;
: set-new-record ( subseq -- subseq )
dup length lcs-so-far set ;
: check-for-record ( original md5 -- original )
2dup is-a-record? [
set-new-record [ print-solutions ] dip nip
"Subsequence: " write hex-string print nl flush
] [ 2drop ] if ;
: (increment) ( i bytes -- bytes )
2dup [ 1+ ] change-nth 2dup ?nth zero? [
[ 1- ] dip (increment)
] [ nip ] if ;
: increment ( bytes -- bytes+1 )
dup length 1- swap (increment) ;
: (md5game) ( bytes -- )
dup md5 checksum-bytes 2dup = [
"Found!" print print-solutions*
] [
check-for-record increment (md5game)
] if ;
: populate ( -- bytes )
buff_size random-bytes >byte-array ;
: md5game ( -- )
populate 0 lcs-so-far set (md5game) ;
MAIN: md5game
New Annotation