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: 
open System

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

let md5 (plainText : string) =
    plainText,
     BitConverter.ToString(
      Security.Cryptography.MD5.Create().ComputeHash (
       Text.Encoding.ASCII.GetBytes plainText)).Replace("-","").ToLower()

(* 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 -> snd e = md5')
  
(* ("c1a2bb1", "34a79dcbe2670a58abfa4d502ae0fe77") *)
let md = md5 "c1a2bb1"

crmd (snd md) "abc123" 7 
namespace System
namespace Microsoft
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Collections
val md5 : plainText:string -> string * string

Full name: Script.md5
val plainText : string
Multiple items
val string : value:'T -> string

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

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

Full name: Microsoft.FSharp.Core.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
namespace System.Security
namespace System.Security.Cryptography
type MD5 =
  inherit HashAlgorithm
  static member Create : unit -> MD5 + 1 overload

Full name: System.Security.Cryptography.MD5
Security.Cryptography.MD5.Create() : Security.Cryptography.MD5
Security.Cryptography.MD5.Create(algName: string) : Security.Cryptography.MD5
namespace System.Text
type Encoding =
  member BodyName : string
  member Clone : unit -> obj
  member CodePage : int
  member DecoderFallback : DecoderFallback with get, set
  member EncoderFallback : EncoderFallback with get, set
  member EncodingName : string
  member Equals : value:obj -> bool
  member GetByteCount : chars:char[] -> int + 3 overloads
  member GetBytes : chars:char[] -> byte[] + 5 overloads
  member GetCharCount : bytes:byte[] -> int + 2 overloads
  ...

Full name: System.Text.Encoding
property Text.Encoding.ASCII: Text.Encoding
Text.Encoding.GetBytes(s: string) : byte []
Text.Encoding.GetBytes(chars: char []) : byte []
Text.Encoding.GetBytes(chars: char [], index: int, count: int) : byte []
Text.Encoding.GetBytes(chars: nativeptr<char>, charCount: int, bytes: nativeptr<byte>, byteCount: int) : int
Text.Encoding.GetBytes(s: string, charIndex: int, charCount: int, bytes: byte [], byteIndex: int) : int
Text.Encoding.GetBytes(chars: char [], charIndex: int, charCount: int, bytes: byte [], byteIndex: int) : int
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<'b * '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 : 'b * 'a (requires equality)
val snd : tuple:('T1 * 'T2) -> 'T2

Full name: Microsoft.FSharp.Core.Operators.snd
val md : string * string

Full name: Script.md
Next Version Raw view Test code New version

More information

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