-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopp.html
More file actions
119 lines (102 loc) · 3.74 KB
/
Copy pathopp.html
File metadata and controls
119 lines (102 loc) · 3.74 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
<!DOCTYPE html>
<html>
<head>
<title>One-time Password Parser</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link rel="shortcut icon" href="favicon.ico"/>
</head>
<body>
<!--<a href="http://jsfiddle.net/russau/ch8PK/?utm_source=website&utm_medium=embed&utm_campaign=ch8PK">参考网站</a>-->
<div class="container-fluid">
<div class="span6" style="border-style:solid;border-width:1px;margin: 60px">
<div class="text-center ">
<h3>谷歌验证码 解码器</h3>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="secret">秘钥 (base32)</label>
<div class="controls">
<input type="text" id="secret" class="input-medium"
value="JBSWY3DPEHPK3PXP"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="otp">动态密码</label>
<div class="controls">
<input type="text" id="otp" class="input-medium">
</div>
</div>
<div class="control-group">
<label class="control-label" for="updatingIn">剩余时间</label>
<div class="controls">
<input type="text" id="updatingIn" class="input-medium">
</div>
</div>
</form>
</div>
</div>
</div>
<script src="jquery.js"></script>
<script src="sha.js"></script>
<script>
function dec2hex(s) {
return (s < 15.5 ? '0' : '') + Math.round(s).toString(16);
}
function hex2dec(s) {
return parseInt(s, 16);
}
function base32tohex(base32) {
var base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
var bits = "";
var hex = "";
for (var i = 0; i < base32.length; i++) {
var val = base32chars.indexOf(base32.charAt(i).toUpperCase());
bits += leftpad(val.toString(2), 5, '0');
}
for (var i = 0; i + 4 <= bits.length; i += 4) {
var chunk = bits.substr(i, 4);
hex = hex + parseInt(chunk, 2).toString(16);
}
return hex;
}
function leftpad(str, len, pad) {
if (len + 1 >= str.length) {
str = Array(len + 1 - str.length).join(pad) + str;
}
return str;
}
function updateOtp() {
var key = base32tohex($('#secret').val());
var epoch = Math.round(new Date().getTime() / 1000.0);
var time = leftpad(dec2hex(Math.floor(epoch / 30)), 16, '0');
// updated for jsSHA v2.0.0 - http://caligatio.github.io/jsSHA/
var shaObj = new jsSHA("SHA-1", "HEX");
shaObj.setHMACKey(key, "HEX");
shaObj.update(time);
var hmac = shaObj.getHMAC("HEX");
var offset = hex2dec(hmac.substring(hmac.length - 1));
var otp = (hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff')) + '';
otp = (otp).substr(otp.length - 6, 6);
$('#otp').val(otp);
}
function timer() {
var epoch = Math.round(new Date().getTime() / 1000.0);
var countDown = 30 - (epoch % 30);
if (epoch % 30 === 0) updateOtp();
$('#updatingIn').val(countDown);
}
$(function () {
updateOtp();
$('#update').click(function (event) {
updateOtp();
event.preventDefault();
});
$('#secret').keyup(function () {
updateOtp();
});
setInterval(timer, 1000);
});
</script>
</body>
</html>