-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
280 lines (256 loc) · 9.31 KB
/
Copy pathscript.js
File metadata and controls
280 lines (256 loc) · 9.31 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/* PASSWORD_AUDIT.exe — behavior
Extracted from index.html. Expects the DOM structure and IDs defined
there (matrix canvas, #pwd input, .meter-seg elements, #console, etc.)
to already exist when this file runs. */
/* ============ MATRIX RAIN ============ */
const canvas = document.getElementById('matrix');
const ctx = canvas.getContext('2d');
let W, H, columns, drops;
const glyphs = 'アイウエオカキクケコサシスセソ0123456789$#@!%&*+-<>?/\\';
function initMatrix(){
W = canvas.width = window.innerWidth;
H = canvas.height = window.innerHeight;
const fontSize = 15;
columns = Math.floor(W / fontSize);
drops = new Array(columns).fill(0).map(()=>Math.random()*-50);
}
window.addEventListener('resize', initMatrix);
initMatrix();
function drawMatrix(){
ctx.fillStyle = 'rgba(6,10,8,0.09)';
ctx.fillRect(0,0,W,H);
const fontSize = 15;
ctx.font = fontSize + 'px monospace';
for(let i=0;i<columns;i++){
const text = glyphs[Math.floor(Math.random()*glyphs.length)];
const x = i*fontSize;
const y = drops[i]*fontSize;
const grad = ctx.createLinearGradient(0,y-fontSize,0,y);
ctx.fillStyle = Math.random() > 0.975 ? '#d9ffe6' : 'rgba(0,255,106,0.75)';
ctx.fillText(text, x, y);
if(y > H && Math.random() > 0.975){
drops[i] = 0;
}
drops[i]++;
}
requestAnimationFrame(drawMatrix);
}
drawMatrix();
/* ============ PASSWORD LOGIC ============ */
const pwdInput = document.getElementById('pwd');
const toggleVis = document.getElementById('toggleVis');
const consoleEl = document.getElementById('console');
const crackTimeEl = document.getElementById('crack-time');
const crackNoteEl = document.getElementById('crack-note');
const verdictLabel = document.getElementById('verdict-label');
const meterSegs = document.querySelectorAll('.meter-seg');
const statLen = document.getElementById('stat-len');
const statCharset = document.getElementById('stat-charset');
const statEntropy = document.getElementById('stat-entropy');
const statCombos = document.getElementById('stat-combos');
const COMMON_PASSWORDS = new Set([
'password','123456','123456789','qwerty','abc123','password1','111111',
'iloveyou','admin','welcome','monkey','dragon','letmein','football',
'password123','12345678','sunshine','princess','qwerty123','trustno1',
'passw0rd','starwars','master','hello','freedom','whatever','shadow',
'superman','michael','ninja','azerty','000000','123123'
]);
toggleVis.addEventListener('click', ()=>{
const isPwd = pwdInput.type === 'password';
pwdInput.type = isPwd ? 'text' : 'password';
toggleVis.textContent = isPwd ? '[ HIDE ]' : '[ SHOW ]';
});
function hasSequential(str){
const seqs = ['0123456789','abcdefghijklmnopqrstuvwxyz','qwertyuiop','asdfghjkl','zxcvbnm'];
const low = str.toLowerCase();
for(const seq of seqs){
for(let i=0;i<=seq.length-3;i++){
if(low.includes(seq.substring(i,i+3))) return true;
}
}
return false;
}
function hasRepeatRun(str){
return /(.)\1\1/.test(str);
}
function computeCharsetSize(pwd){
let size = 0;
if(/[a-z]/.test(pwd)) size += 26;
if(/[A-Z]/.test(pwd)) size += 26;
if(/[0-9]/.test(pwd)) size += 10;
if(/[^a-zA-Z0-9]/.test(pwd)) size += 33;
return size;
}
function formatTime(seconds){
if(!isFinite(seconds)) return 'HEAT DEATH OF THE UNIVERSE';
if(seconds < 1) return 'INSTANTLY';
const units = [
['century', 3153600000],
['year', 31536000],
['day', 86400],
['hour', 3600],
['minute', 60],
['second', 1]
];
// very large numbers -> use scientific notation of years
const years = seconds / 31536000;
if(years > 1e6){
return years.toExponential(2) + ' years';
}
for(const [name, secs] of units){
if(seconds >= secs){
const val = seconds/secs;
return (val>=100? Math.round(val).toLocaleString() : val.toFixed(1)) + ' ' + name + (val>=2?'s':'');
}
}
return seconds.toFixed(2)+' seconds';
}
function formatCombos(n){
if(n < 1000) return Math.round(n).toString();
return n.toExponential(2);
}
let consoleTimer = null;
const fakeHashChars = '0123456789abcdef';
function randomHash(len){
let s='';
for(let i=0;i<len;i++) s+= fakeHashChars[Math.floor(Math.random()*16)];
return s;
}
function logLine(text, cls){
const div = document.createElement('div');
if(cls) div.className = cls;
div.textContent = text;
consoleEl.appendChild(div);
consoleEl.scrollTop = consoleEl.scrollHeight;
while(consoleEl.children.length > 40){
consoleEl.removeChild(consoleEl.firstChild);
}
}
function runConsoleSim(pwd, verdict){
clearInterval(consoleTimer);
consoleEl.innerHTML = '';
if(!pwd){
logLine('waiting for target string...');
return;
}
logLine('[*] target acquired, length='+pwd.length);
logLine('[*] loading rockyou.txt + rule engine...');
let attempts = 0;
const maxAttempts = verdict.score <= 1 ? 14 : 26;
consoleTimer = setInterval(()=>{
attempts++;
const guess = randomHash(Math.max(6,pwd.length));
if(attempts >= maxAttempts){
clearInterval(consoleTimer);
if(verdict.score <= 1){
logLine('[!] MATCH FOUND: "'+pwd+'" ← cracked', 'hit');
logLine('[!] time elapsed: '+formatTime(verdict.seconds).toLowerCase(), 'hit');
} else {
logLine('[x] dictionary exhausted, 0 matches', 'ok');
logLine('[x] switching to brute force... est. '+formatTime(verdict.seconds).toLowerCase(), 'ok');
logLine('[✓] target password holding strong', 'ok');
}
return;
}
logLine('[' + String(attempts).padStart(3,'0') + '] trying → '+guess+' ✗');
}, 90);
}
function evaluate(pwd){
const len = pwd.length;
const charset = computeCharsetSize(pwd) || 1;
const entropy = len * Math.log2(charset || 1);
const combos = Math.pow(charset, len);
const guessesPerSecond = 1e10; // offline fast hash attack assumption
let seconds = combos / guessesPerSecond / 2; // average case
const isCommon = COMMON_PASSWORDS.has(pwd.toLowerCase());
if(isCommon) seconds = Math.min(seconds, 0.5);
if(hasSequential(pwd) || hasRepeatRun(pwd)) seconds = seconds * 0.001;
// score 0-4
let score = 0;
if(len >= 8) score++;
if(len >= 12) score++;
if(charset >= 36) score++;
if(charset >= 70) score++;
if(isCommon || len < 6) score = 0;
score = Math.min(score,4);
return {len, charset, entropy, combos, seconds, score, isCommon};
}
function updateChecklist(pwd){
const rules = {
len8: pwd.length >= 8,
len12: pwd.length >= 12,
lower: /[a-z]/.test(pwd),
upper: /[A-Z]/.test(pwd),
digit: /[0-9]/.test(pwd),
symbol: /[^a-zA-Z0-9]/.test(pwd),
common: pwd.length>0 && !COMMON_PASSWORDS.has(pwd.toLowerCase()),
repeat: pwd.length>0 && !hasSequential(pwd) && !hasRepeatRun(pwd)
};
document.querySelectorAll('.check-item').forEach(item=>{
const rule = item.dataset.rule;
const pass = rules[rule];
item.classList.toggle('pass', !!pass);
item.querySelector('.icon').textContent = pass ? '✓' : '○';
});
}
const scoreMeta = [
{label:'— EMPTY —', color:'var(--text-dim)'},
{label:'CRITICAL — CRACKED IN SECONDS', color:'var(--red)'},
{label:'WEAK — TRIVIAL TO BREACH', color:'var(--red)'},
{label:'FAIR — VULNERABLE', color:'var(--amber)'},
{label:'STRONG — SOLID DEFENSE', color:'var(--green)'},
{label:'FORTRESS — GOOD LUCK, HACKER', color:'var(--cyan)'}
];
function updateMeter(score, pwdEmpty){
const activeCount = pwdEmpty ? 0 : score+1;
const meta = pwdEmpty ? scoreMeta[0] : scoreMeta[score+1];
meterSegs.forEach((seg,i)=>{
seg.classList.toggle('on', i < activeCount);
seg.style.background = i < activeCount ? meta.color : '';
seg.style.color = meta.color;
});
verdictLabel.textContent = meta.label;
verdictLabel.style.color = meta.color;
}
function render(){
const pwd = pwdInput.value;
if(!pwd){
updateMeter(0,true);
statLen.textContent='0';
statCharset.textContent='0';
statEntropy.textContent='0 bits';
statCombos.textContent='0';
crackTimeEl.textContent = 'INSTANT';
crackTimeEl.style.color = 'var(--text-dim)';
crackNoteEl.textContent = '— type something to begin the audit —';
updateChecklist('');
runConsoleSim('', {score:0, seconds:0});
return;
}
const v = evaluate(pwd);
updateMeter(v.score, false);
statLen.textContent = v.len;
statCharset.textContent = v.charset + ' symbols';
statEntropy.textContent = v.entropy.toFixed(1)+' bits';
statCombos.textContent = formatCombos(v.combos);
const timeStr = formatTime(v.seconds);
crackTimeEl.textContent = timeStr.toUpperCase();
const meta = scoreMeta[v.score+1];
crackTimeEl.style.color = meta.color;
crackTimeEl.style.textShadow = '0 0 20px '+meta.color;
if(v.isCommon){
crackNoteEl.textContent = 'this is one of the most common passwords on Earth. every attacker tries it first.';
} else if(v.score <= 1){
crackNoteEl.textContent = 'short and/or simple — automated tools chew through this in a blink.';
} else if(v.score === 2){
crackNoteEl.textContent = 'better, but a determined attacker with GPUs will get there eventually.';
} else if(v.score === 3){
crackNoteEl.textContent = 'good spread of characters and length. keep it unique per site.';
} else {
crackNoteEl.textContent = 'excellent entropy. this password could outlive most hardware trying to guess it.';
}
updateChecklist(pwd);
runConsoleSim(pwd, v);
}
pwdInput.addEventListener('input', render);
render();