Skip to content

Commit

Permalink
Update totp.js
Browse files Browse the repository at this point in the history
  • Loading branch information
M3351AN authored Feb 23, 2024
1 parent d293e50 commit 045adc4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions js/totp.js
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
function getUTCTime() {
var date = new Date();
var year = date.getUTCFullYear();
var month = date.getUTCMonth() + 1;
var day = date.getUTCDate();
var hour = date.getUTCHours();
var minute = date.getUTCMinutes();
return [year, month, day, hour, minute];
}

function generateCode(utcTime) {
var sum = 0;
for (var i = 0; i < 5; i++) {
sum += utcTime[i];
}
var code = sum ^ 3351 % 10000;
return code;
}

function displayTimeAndCode() {
var utcTime = getUTCTime();
var code = generateCode(utcTime);
var timeString = utcTime.join(":");
var codeString = code.toString();
var remaining = 60 - (Date.now() / 1000) % 60;
document.getElementById("time").innerHTML = timeString;
document.getElementById("code").innerHTML = codeString;
document.getElementById("progress").value = remaining;
}

0 comments on commit 045adc4

Please sign in to comment.