Skip to content

Instantly share code, notes, and snippets.

@ktakashi
Created February 10, 2014 12:22
Show Gist options
  • Save ktakashi/8914937 to your computer and use it in GitHub Desktop.
Save ktakashi/8914937 to your computer and use it in GitHub Desktop.
JAL password hash
(import (rnrs) (crypto) (math) (time))
(define target (hash MD5 (string->utf8 "hoge$567890")))
(print target)
(define (solve)
(define md5-hash (hash-algorithm MD5))
(define buf (make-bytevector (hash-size md5-hash)))
(define value (u8-list->bytevector
(append (map char->integer (string->list "hoge$"))
'(0 0 0 0 0 0))))
(define offset (string-length "hoge$"))
(define (->solted-bv v)
(define len (bytevector-length value))
(let loop ((i offset) (ch (string->list (number->string v))))
(cond ((null? ch) value)
(else
(bytevector-u8-set! value i (char->integer (car ch)))
(loop (+ i 1) (cdr ch))))))
(let loop ((i 0))
(when (< i 1000000)
(hash-init! md5-hash)
(hash-process! md5-hash (->solted-bv i))
(hash-done! md5-hash buf)
(if (bytevector=? target buf)
buf
(loop (+ i 1))))))
(print "Solved: " (time (solve)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment