2 people like it.

md5 cracking

Simple md5 cracker, example of using permutations and pseq rather than cracking.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
open System

#r "FSharp.PowerPack.Parallel.Seq";;
open Microsoft.FSharp.Collections

let MD5 = new MD5CryptoServiceProvider()

let alignMD5 (md : string) = 
  md.Replace("-","").ToLower() 

(* new md5, much faster, no create()*)
let md5 (s : string) = 
  Encoding.UTF8.GetBytes s
  |> MD5.ComputeHash
  |> BitConverter.ToString
  |> alignMD5

(* perm code from
   http://stackoverflow.com/questions/4495597/combinations-and-permutations-in-f 

   Generates the cartesian outer product of a list of sequences LL *)
let rec outerProduct = function
  | []    -> Seq.singleton []
  | L::Ls -> L |> Seq.collect (fun x -> 
                  outerProduct Ls |> Seq.map (fun L -> x::L))

(* Generates all n-element combination from a list L *)
let getPermsWithRep n L = 
    List.replicate n L |> outerProduct  
 
let listToStr xs = 
   List.toArray xs |> fun c -> new string (c)

let crmd md5' (charset : string) n = 

  getPermsWithRep n (charset |> Seq.toList)
  |> PSeq.map (PSeq.toList >> listToStr >> md5) 

  |> Seq.filter (fun e -> e = md5')
  
(* ("c1a2bb1", "34a79dcbe2670a58abfa4d502ae0fe77") *)
let md = md5 "c1a2bb1"

crmd md "abc123" 7 
namespace System
namespace Microsoft
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Collections
val MD5 : obj

Full name: Script.MD5
val alignMD5 : md:string -> string

Full name: Script.alignMD5
val md : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
String.Replace(oldValue: string, newValue: string) : string
String.Replace(oldChar: char, newChar: char) : string
val md5 : s:string -> string

Full name: Script.md5
val s : string
type BitConverter =
  static val IsLittleEndian : bool
  static member DoubleToInt64Bits : value:float -> int64
  static member GetBytes : value:bool -> byte[] + 9 overloads
  static member Int64BitsToDouble : value:int64 -> float
  static member ToBoolean : value:byte[] * startIndex:int -> bool
  static member ToChar : value:byte[] * startIndex:int -> char
  static member ToDouble : value:byte[] * startIndex:int -> float
  static member ToInt16 : value:byte[] * startIndex:int -> int16
  static member ToInt32 : value:byte[] * startIndex:int -> int
  static member ToInt64 : value:byte[] * startIndex:int -> int64
  ...

Full name: System.BitConverter
BitConverter.ToString(value: byte []) : string
BitConverter.ToString(value: byte [], startIndex: int) : string
BitConverter.ToString(value: byte [], startIndex: int, length: int) : string
val outerProduct : _arg1:#seq<'b> list -> seq<'b list>

Full name: Script.outerProduct
module Seq

from Microsoft.FSharp.Collections
val singleton : value:'T -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.singleton
val L : #seq<'b>
val Ls : #seq<'b> list
val collect : mapping:('T -> #seq<'U>) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.collect
val x : 'b
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val L : 'b list
val getPermsWithRep : n:int -> L:seq<'a> -> seq<'a list>

Full name: Script.getPermsWithRep
val n : int
val L : seq<'a>
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val replicate : count:int -> initial:'T -> 'T list

Full name: Microsoft.FSharp.Collections.List.replicate
val listToStr : xs:char list -> string

Full name: Script.listToStr
val xs : char list
val toArray : list:'T list -> 'T []

Full name: Microsoft.FSharp.Collections.List.toArray
val c : char []
val crmd : md5':'a -> charset:string -> n:int -> seq<'a> (requires equality)

Full name: Script.crmd
val md5' : 'a (requires equality)
val charset : string
val toList : source:seq<'T> -> 'T list

Full name: Microsoft.FSharp.Collections.Seq.toList
val filter : predicate:('T -> bool) -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.filter
val e : 'a (requires equality)
val md : string

Full name: Script.md

More information

Link:http://fssnip.net/ay
Posted:12 years ago
Author:david klein
Tags: md5 cracking , pseq