dn42-info/html/port-calc.html

48 lines
1.3 KiB
HTML
Raw Normal View History

2024-05-12 16:45:33 +02:00
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>dn724</title>
<input type="number" min="0" placeholder="your ASN" oninput="calculate(this)">
<p>Port: <span id="result"></span></p>
<script>
const result = document.getElementById('result');
const isNumber = (s) => /^\d+$/.test(s);
function calculate(el) {
console.log(el);
if (el.value == '') {
result.innerText = '';
return;
}
let cand = cyrb53(el.value).toString().slice(0, 5);
if (cand > 65535 || cand < 30000) {
cand = (cand % 3 + 3) * 10000 + (cand % 10000);
}
result.innerText = cand;
}
const cyrb53 = (str, seed = 0) => {
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
for(let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
};
</script>
</html>