Web tool - given a hash, compute day and time
This commit is contained in:
parent
a8ef87496c
commit
cd340eb345
180
index.html
Normal file
180
index.html
Normal file
@ -0,0 +1,180 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- cSpell:ignore blocksize Cbase hhmmss modbus XXYY yaacov -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||
<title>Queue Computer</title>
|
||||
<!-- <link rel="stylesheet" href="./style.css"> -->
|
||||
<!-- <link rel="icon" href="./favicon.ico" type="image/x-icon"> -->
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
/**
|
||||
* Calculates the buffers CRC16.
|
||||
*
|
||||
* @param buffer the data buffer.
|
||||
* @return the calculated CRC16.
|
||||
*
|
||||
* Source: github.com/yaacov/node-modbus-serial
|
||||
*/
|
||||
const crc16 = (buffer) => {
|
||||
let crc = 0xffff;
|
||||
// let crc = 0x0000;
|
||||
let odd;
|
||||
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
crc = crc ^ buffer[i];
|
||||
|
||||
for (let j = 0; j < 8; j++) {
|
||||
odd = crc & 0x0001;
|
||||
crc = crc >> 1;
|
||||
if (odd) {
|
||||
crc = crc ^ 0xa001;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return crc.toString(16).toUpperCase();
|
||||
};
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
const doThing = () => {
|
||||
updateString();
|
||||
const start = new Date();
|
||||
let itr = 0;
|
||||
const matches = [];
|
||||
const staticFront = front(); // Single document call is faster in loop critical path
|
||||
const staticBack = back(); // Single document call is faster in loop critical path
|
||||
|
||||
const queue = document.getElementById("queue").value;
|
||||
for (let day = 1; day < 31; day++) {
|
||||
for (let hour = 0; hour < 24; hour++) {
|
||||
for (let minute = 0; minute < 60; minute++) {
|
||||
for (let second = 0; second < 60; second++) {
|
||||
itr++;
|
||||
const dtg =
|
||||
// 123456789 : 4B37
|
||||
|
||||
// "20230610151423:flamp-file.k2s1base6464" : D5C6
|
||||
|
||||
// "20230610" +
|
||||
// ("00" + hour).slice(-2) +
|
||||
// ("00" + minute).slice(-2) +
|
||||
// ("00" + second).slice(-2) +
|
||||
// ":flamp-file.k2s1base6464";
|
||||
|
||||
staticFront +
|
||||
("00" + day).slice(-2) +
|
||||
("00" + hour).slice(-2) +
|
||||
("00" + minute).slice(-2) +
|
||||
("00" + second).slice(-2) +
|
||||
staticBack;
|
||||
|
||||
const res = crc16(encoder.encode(dtg));
|
||||
if (res === queue) {
|
||||
matches.push([
|
||||
("00" + day).slice(-2) +
|
||||
" " +
|
||||
("00" + hour).slice(-2) +
|
||||
":" +
|
||||
("00" + minute).slice(-2) +
|
||||
":" +
|
||||
("00" + second).slice(-2),
|
||||
dtg,
|
||||
]);
|
||||
console.log({
|
||||
msg: "MATCH!!!",
|
||||
dtg,
|
||||
time: hour + ":" + minute + ":" + second,
|
||||
res,
|
||||
itr,
|
||||
});
|
||||
}
|
||||
// console.log({ res });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const end = new Date();
|
||||
|
||||
let report = matches.map((arr) => arr.join(" - ")).join("\n");
|
||||
|
||||
console.log({
|
||||
matchesCount: matches.length,
|
||||
matches,
|
||||
itr,
|
||||
start,
|
||||
end,
|
||||
diff: end.getTime() - start.getTime(),
|
||||
});
|
||||
|
||||
report =
|
||||
report +
|
||||
"\n\nFound " +
|
||||
matches.length +
|
||||
" matches in " +
|
||||
(end.getTime() - start.getTime()) +
|
||||
" milliseconds.";
|
||||
|
||||
document.getElementById("results").value = report;
|
||||
};
|
||||
|
||||
const front = () => document.getElementById("date").value;
|
||||
const back = () =>
|
||||
":" +
|
||||
document.getElementById("filename").value +
|
||||
(document.getElementById("compressed").checked ? "1" : "0") +
|
||||
document.getElementById("encoding").value +
|
||||
document.getElementById("blocksize").value;
|
||||
|
||||
const updateString = () => {
|
||||
document.getElementById("dtgAndMore").innerHTML =
|
||||
front() + "DDhhmmss" + back();
|
||||
};
|
||||
</script>
|
||||
<main>
|
||||
<h1>Queue Computer for the Month</h1>
|
||||
<p>
|
||||
<label for="queue">Queue</label>
|
||||
<input id="queue" value="D5C6" onchange="updateString()" /><br />
|
||||
<label for="date">Date</label>
|
||||
<input id="date" value="202306" onchange="updateString()" /><br />
|
||||
<label for="filename">Filename</label>
|
||||
<input
|
||||
id="filename"
|
||||
value="flamp-file.k2s"
|
||||
onchange="updateString()"
|
||||
/><br />
|
||||
<label for="compressed">Compressed</label>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="compressed"
|
||||
checked
|
||||
onchange="updateString()"
|
||||
/><br />
|
||||
<label for="encoding">Encoding</label>
|
||||
<select id="encoding" value="base64" onchange="updateString()">
|
||||
<option value="base64" selected>base64</option>
|
||||
<option value="base128">base128</option>
|
||||
<option value="base256">base256</option></select
|
||||
><br />
|
||||
<label for="blocksize">BlockSize</label>
|
||||
<select id="blocksize" value="64" onchange="updateString()">
|
||||
<option value="32">32</option>
|
||||
<option value="64" selected>64</option>
|
||||
<option value="128">128</option>
|
||||
<option value="256">256</option></select
|
||||
><br />
|
||||
<label id="dtgAndMore">YYYYMMDDhhmmss:filenameCbaseXXYY</label>
|
||||
</p>
|
||||
<button onclick="doThing()">Do the Thing!</button><br />
|
||||
<label for="results">Results</label>
|
||||
<textarea type="text" cols="55" rows="12" id="results" value=""></textarea
|
||||
><br />
|
||||
</main>
|
||||
<!-- <script src="index.js"></script> -->
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user