diff --git a/src/calculator/index.html b/src/calculator/index.html new file mode 100644 index 0000000..6eaa8f3 --- /dev/null +++ b/src/calculator/index.html @@ -0,0 +1,19 @@ + + + + +
Port:
+ + \ No newline at end of file diff --git a/src/calculator/script.js b/src/calculator/script.js new file mode 100644 index 0000000..8f47950 --- /dev/null +++ b/src/calculator/script.js @@ -0,0 +1,32 @@ +const result = document.getElementById('result'); +const isNumber = (s) => /^\d+$/.test(s); + +function calculate(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); +}; \ No newline at end of file diff --git a/src/index.html b/src/index.html index bd4f50b..d485c99 100644 --- a/src/index.html +++ b/src/index.html @@ -44,7 +44,6 @@Peering requirements
@@ -60,7 +59,7 @@Contact
@@ -71,4 +70,10 @@Other
+