-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode.js
More file actions
24 lines (18 loc) · 818 Bytes
/
decode.js
File metadata and controls
24 lines (18 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Define an encoded string using invisible characters
const encodedString = '';
// Create a binary string by replacing the Unicode characters
const binaryString = encodedString
// Replace U+200C ZERO WIDTH NON-JOINER with '0'
.replace(//g, 0)
// Replace U+200D ZERO WIDTH JOINER with '1'
.replace(//g, 1);
// Split the binary string into 8-bit chunks (1 byte each)
const byteStrings = binaryString.match(/.{1,8}/g);
// Convert each 8-bit binary chunk into an integer
const byteArray = byteStrings.map((byte) => parseInt(byte, 2));
// Create an unsigned int(8) array from the byte array
const uint8Array = new Uint8Array(byteArray).buffer;
// Decode the byte array into a string
const decodedCode = new TextDecoder().decode(uint8Array);
// Log the decoded code in the console
console.log(decodedCode);