Commit 152ce662 authored by Chris Müller's avatar Chris Müller
Browse files

Move md5brute.cherry to docs/examples

parent ae46e69f
(let alphabet (string->tuple "abcd"))
(let alphabet-size (length alphabet))
(define (plain indices)
(list->string (map (lambda (index) (nth alphabet index)) indices)))
(define (update indices)
(loop (increment (past indices))
(if (null? past)
(raise "test")
(if (< (head past) (- alphabet-size 1))
(cons (+ (head past) 1) (tail past))
(cons 0 (increment (tail past)))))))
(define (crack hash n)
(loop (generator (ts (time)) (m 0) (indices (make-list n 0)))
(if (not (null? indices))
(begin
(let key (plain indices))
(if (string-equal? (md5 key) hash)
key
(try
(if (> (- (time) ts) 1)
(begin
(println m " hashes/sec")
(generator (time) 0 (update indices)))
(generator ts (+ m 1) (update indices)))
(catch (e) (generator ts m '())))))
'())))
(define (main arg_min arg_max arg_pass)
(let min (string->fixnum arg_min))
(let max (string->fixnum arg_max))
(let hash (md5 arg_pass))
(loop (words (n min))
(if (=< n max)
(if (null? (crack hash n))
(words (+ n 1))
(begin
(println arg_pass " found.")
(exit 0)))
(println "No MD5 hash found"))))
;; Booleans
(let yes true)
(let no false)
;; Numbers
(let hex 0xFF)
(let oct 0777)
(let bin 0b1111)
(let dez 10)
;; Characters
(let space \space)
(let newline \newline)
(let A \A)
(let tab \tab)
;; Strings and Raw-Strings
(let string "teststring\n")
(let rawstring ~[a-zA-Z]+@[a-zA-Z]+\.de~)
;; Pair definition
(define (complex real imag)
(cons real imag))
;; List defintion
(define (point x y z)
(let withcons (cons x (cons y (cons z '()))))
(let withlist (list x y z))
withlist)
;; Tuple definition (vectors)
(define (pointd x y z)
(tuple x y z))
;; Function definitions
(define (function a b)
(println a " --- " b))
;; Lambda expressions (anonymous functions)
(define (bla a)
(let smaller (lambda (b) (< a b)))
(smaller 10))
;; if statements (supported operators: and, or, not, <, >, >=, =<, =)
(define (max a b)
(if (or (and (1 > a) (2 < b))
(not false)
true)
(println "True")
(if (= a b)
(println "a = b")
(pritnln "a != b"))))
;; named let / recursive looping
(define (range from to)
(loop (add (x from) (xs '()))
(if (< x to)
(add (+ x 1) (cons x xs))
(cons (+ x 1) xs))))
;; exit methods
(define (quit) (exit 0))
(define (abort) (exit 1))
(let alphabet (string->tuple "abcdefghijklmnopqrstuvwxyz"))
(let alphabet-size (length alphabet))
(define (plain indices)
(list->string (map (lambda (index) (nth alphabet index)) indices)))
(define (update indices)
(loop (increment (past indices))
(if (null? past)
(raise "End of indices update range reached"))
(if (< (head past) (- alphabet-size 1))
(cons (+ (head past) 1) (tail past))
(cons 0 (increment (tail past))))))
(define (crack digest n)
(loop (generator (indices (make-list n 0)))
(println (plain indices))
(generator (update indices))))
(define (main arg_min arg_max arg_digest)
(let min (string->fixnum arg_min))
(let max (string->fixnum arg_max))
(loop (words (n min))
(if (=< n max)
(begin
(try
(crack arg_digest n)
(catch (e) (println "No MD5-Hash of length " n " found (" e ")")))
(words (+ n 1)))
(println "No MD5 hash found"))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment