-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
148 lines (120 loc) · 4.06 KB
/
index.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>hash-identifier (v1.2)</title>
<meta name="description" content="Given a hash, find its algorithm.">
<meta name="author" content="cadesalaberry">
<style type="text/css">
</style>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="https://storage.googleapis.com/code.getmdl.io/1.0.6/material.indigo-pink.min.css">
<script src="https://storage.googleapis.com/code.getmdl.io/1.0.6/material.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<div class="mdl-layout-spacer"></div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-textfield--align-right">
<form id="form">
<label class="mdl-button mdl-js-button mdl-button--icon"
for="hash" onclick="check_hash()">
<i class="material-icons">search</i>
</label>
<div class="mdl-textfield__input-holder" >
<input class="mdl-textfield__input" type="text" name="sample" id="hash" placeholder="Type in a hash...">
</div>
</form>
</div>
<div class="mdl-layout-spacer"></div>
</div>
</header>
<main class="mdl-layout__content" style="width:100%">
<div class="page-content">
<table class="mdl-data-table mdl-js-data-table" style="width:100%" >
<tbody id="result">
<tr>
<td class="mdl-data-table__cell--non-numeric">Please enable javascript.</td>
</tr>
</tbody>
</table>
</div>
</main>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
var hash_db = [];
var actions = {
letters_only: function (hash, expected) {
return expected === /^[A-z]+$/.test(hash);
},
alnumeric: function (hash, expected) {
return expected === /^[A-z0-9]+$/.test(hash);
},
digits_only: function (hash, expected) {
return expected === /^[0-9]+$/.test(hash);
},
starts_with: function (hash, expected) {
return expected === hash.slice(0, expected.length);
},
colon_index: function (hash, expected) {
return expected === hash.indexOf(":");
}
};
function satisfy_rules(hash, rules) {
// $.each(rules, function (key, val) {
for (key in rules) {
val = rules[key];
var valid = actions[key](hash, val);
if (!valid) {
console.log(valid + ":" + key + ":" + val);
return false;
}
}
// );
return true;
}
function hash_sorter(a, b) {
return a.id - b.id;
}
function check_hash() {
var hash = $('#hash').val();
console.log("Checking Hash: " + hash);
var possibilities = [];
results = hash_db.filter(function (item) {
return (
hash.length === item['size']
&&
satisfy_rules(hash, item['rules'])
);
});
results.sort(hash_sorter);
var json = JSON.stringify(results, null, 2);
if (results.length === 0) results = [{"name":"No match found."}];
var list = "";
results.forEach(function (item) {
list += "<tr><td class='mdl-data-table__cell--non-numeric'>";
list += item.name;
list += "</td></tr>\n";
});
$('#result').html(list);
}
$.getJSON( "./hash-identifier.db.min.json", function( data ) {
hash_db = data;//.slice(0, 10);
$('#form').submit();
});
$('#form').on('input', function() {
$(this).submit() // get the current value of the input field.
});
$('#form').submit(function(e) {
e.preventDefault();
check_hash();
return false;
});
</script>
</body>
</html>