Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit cd6dfa2

Browse files
authored
Update index.html
Signed-off-by: Blake Arnold <[email protected]>
1 parent a20ed02 commit cd6dfa2

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

index.html

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,37 +59,27 @@
5959
selectedTab.classList.add('active');
6060
}
6161

62-
// Convert a string to BigInt
63-
function stringToBigInt(str) {
64-
// Use the UTF-16 character codes of the string, join them, and turn into BigInt
65-
let charCodes = Array.from(str).map(char => char.charCodeAt(0)).join('');
66-
return BigInt(charCodes);
62+
// Convert a string to BigInt using fixed-width (5 digits) encoding
63+
function stringToBigInt(str) {
64+
// Pad each char code to 5 digits to ensure unambiguous decoding
65+
let charCodes = Array.from(str).map(char => char.charCodeAt(0).toString().padStart(5, '0')).join('');
66+
return BigInt(charCodes);
67+
}
68+
69+
// Convert a BigInt back to a string, decoding in fixed-width (5 digits)
70+
function bigIntToString(bigInt) {
71+
let strRepresentation = bigInt.toString();
72+
// Pad left if string length is not a multiple of 5
73+
if (strRepresentation.length % 5 !== 0) {
74+
strRepresentation = strRepresentation.padStart(Math.ceil(strRepresentation.length / 5) * 5, '0');
6775
}
68-
69-
// Convert a BigInt back to a string
70-
function bigIntToString(bigInt) {
71-
const charCodes = [];
72-
let strRepresentation = bigInt.toString();
73-
74-
// Process the string representation of the BigInt as character codes in reverse
75-
while (strRepresentation.length > 0) {
76-
// Extract the last 2-3 digits (UTF-16 character code ranges from 0 to 65535)
77-
let charCode = parseInt(strRepresentation.slice(-3), 10);
78-
79-
// If the charCode is invalid, try 2 digits
80-
if (charCode > 65535) {
81-
charCode = parseInt(strRepresentation.slice(-2), 10);
82-
strRepresentation = strRepresentation.slice(0, -2);
83-
} else {
84-
strRepresentation = strRepresentation.slice(0, -3);
85-
}
86-
87-
charCodes.push(charCode);
88-
}
89-
90-
// Reverse the charCodes and convert back to characters
91-
return charCodes.reverse().map(code => String.fromCharCode(code)).join('');
76+
const charCodes = [];
77+
for (let i = 0; i < strRepresentation.length; i += 5) {
78+
let code = parseInt(strRepresentation.slice(i, i+5), 10);
79+
charCodes.push(code);
9280
}
81+
return charCodes.map(code => String.fromCharCode(code)).join('');
82+
}
9383

9484
// Helper function to compute SHA-256 hash
9585
async function sha256(message) {

0 commit comments

Comments
 (0)