Working one-time message encryption and decryption

This commit is contained in:
2025-12-03 16:40:26 +03:00
Unverified
parent d4b1e261d7
commit fcb3dff2c9
18 changed files with 1392 additions and 336 deletions
+11 -1
View File
@@ -33,7 +33,17 @@ export function delay(ms: number): Promise<void> {
}
export function b64(a: Uint8Array): string { return btoa(String.fromCharCode(...a)); }
export function b64(a: Uint8Array): string {
// Use chunked approach to avoid "Maximum call stack size exceeded" for large arrays
// Process in chunks and use apply to avoid spreading large arrays
const chunkSize = 8192;
let binary = '';
for (let i = 0; i < a.length; i += chunkSize) {
const chunk = a.slice(i, i + chunkSize);
binary += String.fromCharCode.apply(null, Array.from(chunk));
}
return btoa(binary);
}
export function ub64(s: string): Uint8Array {
const bin = atob(s);
const arr = new Uint8Array(bin.length);