2 people like it.
Like the snippet!
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:
45:
46:
47:
|
open System
open System.Text
open System.Security.Cryptography
#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) =
s, 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 -> snd e = md5')
(* ("c1a2bb1", "34a79dcbe2670a58abfa4d502ae0fe77") *)
let plaintext = "c1a2bb1"
let md = md5 plaintext
crmd (snd md) "abc123" 7
|
namespace System
namespace System.Text
namespace System.Security
namespace System.Security.Cryptography
namespace Microsoft
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Collections
Multiple items
val MD5 : MD5CryptoServiceProvider
Full name: Script.MD5
--------------------
type MD5 =
inherit HashAlgorithm
static member Create : unit -> MD5 + 1 overload
Full name: System.Security.Cryptography.MD5
Multiple items
type MD5CryptoServiceProvider =
inherit MD5
new : unit -> MD5CryptoServiceProvider
member Initialize : unit -> unit
Full name: System.Security.Cryptography.MD5CryptoServiceProvider
--------------------
MD5CryptoServiceProvider() : unit
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 * string
Full name: Script.md5
val s : string
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 Encoding.UTF8: Encoding
Encoding.GetBytes(s: string) : byte []
Encoding.GetBytes(chars: char []) : byte []
Encoding.GetBytes(chars: char [], index: int, count: int) : byte []
Encoding.GetBytes(chars: nativeptr<char>, charCount: int, bytes: nativeptr<byte>, byteCount: int) : int
Encoding.GetBytes(s: string, charIndex: int, charCount: int, bytes: byte [], byteIndex: int) : int
Encoding.GetBytes(chars: char [], charIndex: int, charCount: int, bytes: byte [], byteIndex: int) : int
HashAlgorithm.ComputeHash(buffer: byte []) : byte []
HashAlgorithm.ComputeHash(inputStream: IO.Stream) : byte []
HashAlgorithm.ComputeHash(buffer: byte [], offset: int, count: int) : byte []
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<'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 plaintext : string
Full name: Script.plaintext
val md : string * string
Full name: Script.md
More information