-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
84 lines (79 loc) · 3.03 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>web-based two factor authentication generator</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
</head>
<body>
<div style="text-align:center;margin-top:320px">
<p style="color: #666;">Secret</p>
<input type="text" id="webSec" style="margin:0 auto;border:solid 1px #ccc;width:360px;outline: none;color: #cccccc;padding: 4px;">
<p style="color: #666;">Code</p>
<div id="webCode" style="font-size:40px;cursor: pointer;"></div>
<p style="color: #666;">Expire</p>
<div id="webRefresh" style="color: red;">2</div>
</div>
</body>
</html>
<script>
let t = null;
let k = '';
let lastCode = '';
let isprivate = false;
function key2code(K,t) {
function sha1(C){
function L(x,b){return x<<b|x>>>32-b;}
var l=C.length,D=C.concat([1<<31]),V=0x67452301,W=0x88888888,
Y=271733878,X=Y^W,Z=0xC3D2E1F0;W^=V;
do D.push(0);while(D.length+1&15);D.push(32*l);
while (D.length){
var E=D.splice(0,16),a=V,b=W,c=X,d=Y,e=Z,f,k,i=12;
function I(x){var t=L(a,5)+f+e+k+E[x];e=d;d=c;c=L(b,30);b=a;a=t;}
for(;++i<77;)E.push(L(E[i]^E[i-5]^E[i-11]^E[i-13],1));
k=0x5A827999;for(i=0;i<20;I(i++))f=b&c|~b&d;
k=0x6ED9EBA1;for(;i<40;I(i++))f=b^c^d;
k=0x8F1BBCDC;for(;i<60;I(i++))f=b&c|b&d|c&d;
k=0xCA62C1D6;for(;i<80;I(i++))f=b^c^d;
V+=a;W+=b;X+=c;Y+=d;Z+=e;
}
return[V,W,X,Y,Z];
}
var k=[],l=[],i=0,j=0,c=0;
for (;i<K.length;){
c=c*32+'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'.
indexOf(K.charAt(i++).toUpperCase());
if((j+=5)>31)k.push(Math.floor(c/(1<<(j-=32)))),c&=31;
}
j&&k.push(c<<(32-j));
for(i=0;i<16;++i)l.push(0x6A6A6A6A^(k[i]=k[i]^0x5C5C5C5C));
var s=sha1(k.concat(sha1(l.concat([0,t])))),o=s[4]&0xF;
return (((s[o>>2]<<8*(o&3)|(o&3?s[(o>>2)+1]>>>8*(4-o&3):0))&-1>>>1)%1000000).toString().padStart(6, "0");
}
function update() {
var e = Math.floor(new Date().getTime()/1000);
var t = Math.floor(e/30);
let left = 30 - (e - (t*30));
let c = key2code(k, t);
if (lastCode != c) document.querySelector('#webCode').innerHTML = c;
lastCode = c;
document.querySelector('#webRefresh').innerHTML = left;
}
// parse url param
const p = window.location.href.split('?code=');
k = p.length > 1? p[1]: '';
document.querySelector('#webSec').value = k;
isprivate = window.location.href.indexOf('?private=1') !== -1;
setInterval(update, 1000);
update();
const onSecretUpdate = (e) => {
k = e.target.value.trim();
k = k.replace(/\s+/g, '');
e.target.value = k;
if (!isprivate) window.history.pushState({state:1}, document.title,'?code='+k);
update();
};
document.querySelector('#webSec').addEventListener('keyup', onSecretUpdate);
document.querySelector('#webSec').addEventListener('input', onSecretUpdate);
document.querySelector('#webSec').addEventListener('focus', e => e.target.setSelectionRange(0, e.target.value.length));
</script>