-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.pluto
90 lines (82 loc) · 2.5 KB
/
script.pluto
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
local function joaat_partial(str, val = 0)
for i = 1, #str do
val = (val + str:byte(i)) & 0xffffffff
val = (val + (val << 10)) & 0xffffffff
val = (val ~ (val >> 6)) & 0xffffffff
end
return val
end
local function joaat_add(val, b)
val = (val + b) & 0xffffffff
val = (val + (val << 10)) & 0xffffffff
val = (val ~ (val >> 6)) & 0xffffffff
return val
end
local function joaat_finalise(val)
val = (val + (val << 3)) & 0xffffffff
val = (val ~ (val >> 11)) & 0xffffffff
val = (val + (val << 15)) & 0xffffffff
return val
end
local high_hash = false
local function is_good_hash(hash)
return high_hash ? hash >= 0xffff0000 : hash < 0x10000
end
local function results_add(results, suffix, hash)
results:insert((document.getElementById("name-prefix").value or "")..$"{suffix} hashes to {string.format("%08x", hash)}\n")
end
local function try_suffix(results, hash_prefix, depth, ...)
depth -= 1
if depth == 0 then
for b = 0x61, 0x7A do
local partial = joaat_add(hash_prefix, b)
local hash = joaat_finalise(partial)
if is_good_hash(hash) then
local t = { ... }
t:insert(1, b)
t:reverse()
local suffix = t:map(string.char):concat()
results_add(results, suffix, hash)
end
end
end
if depth > 0 and #results < 10 then
for b = 0x61, 0x7A do
local partial = joaat_add(hash_prefix, b)
try_suffix(results, partial, depth, b, ...)
end
end
end
local function calc()
local prefix = (document.getElementById("name-prefix").value or ""):lower()
local min_chars_to_add = math.max(1, 6 - #prefix)
local max_chars_to_add = 16 - #prefix
if min_chars_to_add > max_chars_to_add then
document.getElementById("output").textContent = "Impossible"
return
end
high_hash = document.getElementById("high-hash").checked
local partial = joaat_partial(prefix)
local results = {}
if prefix ~= "" then
local hash = joaat_finalise(partial)
if is_good_hash(hash) then
results_add(results, "", hash)
end
end
for chars_to_add = min_chars_to_add, max_chars_to_add do
try_suffix(results, partial, chars_to_add)
if #results >= 10 then
break
end
end
if #results == 0 then
document.getElementById("output").textContent = "No matches found"
else
results:sort(|a, b| -> #a < #b)
document.getElementById("output").textContent = results:concat("")
end
end
calc()
document.getElementById("name-prefix"):addEventListener("input", calc)
document.getElementById("high-hash"):addEventListener("change", calc)