-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday05_part01.fs
27 lines (22 loc) · 884 Bytes
/
day05_part01.fs
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
module day05_part01
let calculateMD5Hash (input: string) =
let md5 = System.Security.Cryptography.MD5.Create()
let inputBytes = System.Text.Encoding.ASCII.GetBytes(input)
let hashBytes = md5.ComputeHash(inputBytes)
let sb = System.Text.StringBuilder()
for i = 0 to hashBytes.Length - 1 do
sb.Append(hashBytes.[i].ToString("X2")) |> ignore
sb.ToString()
let rec findPassword (input: string) (index: int) (password: string) =
let hash = calculateMD5Hash (input + (index.ToString()))
if hash.StartsWith("00000") then
let newPassword = password + (hash.[5].ToString())
if String.length newPassword = 8 then
newPassword
else
findPassword input (index + 1) newPassword
else
findPassword input (index + 1) password
let execute =
let input = "wtnhxymk"
findPassword input 0 ""