From fdd9d998a53068805eb8ced9c2bcfc5a4c0b6aa3 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Tue, 25 Aug 2026 07:55:10 -0700 Subject: [PATCH] Delete: Remove speck48_96ctr.js in favor of TS --- speck48_96ctr.js | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 speck48_96ctr.js diff --git a/speck48_96ctr.js b/speck48_96ctr.js deleted file mode 100644 index 15b2e9b..0000000 --- a/speck48_96ctr.js +++ /dev/null @@ -1,44 +0,0 @@ -import speck from 'generic-speck'; -import { blake2bHex } from 'blakejs'; - -const speck48_96 = speck({ bits: 24, rounds: 23, rightRotations: 8, leftRotations: 3 }); - -export function getKey(kStr) { - const key96bit = blake2bHex(kStr, null, 12); - return[ - parseInt(key96bit.slice(0, 6), 16), - parseInt(key96bit.slice(6, 12), 16), - parseInt(key96bit.slice(12, 18), 16), - parseInt(key96bit.slice(18, 24), 16) - ]; -} - -export function encrypt(ptStr, key) { - // Generate a cryptographically secure random 24-bit nonce - const nonce = globalThis.crypto.getRandomValues(new Uint32Array(1))[0] & 0xFFFFFF; - - const ctArr = Array.from(ptStr, (c, i) => { - const ctrBlock = nonce * 16777216 + (i & 0xFFFFFF); - const ks = speck48_96.encrypt(ctrBlock, key); - return (c.codePointAt(0) ^ ks) >>> 0; - }); - - // Prepend the nonce to the ciphertext array - return [nonce, ...ctArr]; -} - -export function decrypt(numArr, key) { - if (!numArr || numArr.length === 0) return ''; - - // Extract the nonce from the first element - const nonce = numArr[0]; - const ctArr = numArr.slice(1); - - return ctArr.map((ct, i) => { - const ctrBlock = nonce * 16777216 + (i & 0xFFFFFF); - const ks = speck48_96.encrypt(ctrBlock, key); - const cp = (ct ^ ks) >>> 0; - try { return String.fromCodePoint(cp); } - catch { return ''; } - }).join(''); -}