Created
August 1, 2025 20:24
-
-
Save AzureFlow/6acad50c22e1eaca5fc36ab4bfab1b97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @type {{e: string, t: object}} | |
| */ | |
| const data = { | |
| e: "AI0=BY2A07253h8CFjLW8umPTW8u", | |
| t: { | |
| 0: { | |
| 0: { | |
| 0: "b", | |
| 1: { | |
| 0: "c", | |
| 1: "e" | |
| } | |
| }, | |
| 1: { | |
| 0: { | |
| 0: "z", | |
| 1: "t" | |
| }, | |
| 1: { | |
| 0: { | |
| 0: "s", | |
| 1: "p" | |
| }, | |
| 1: { | |
| 0: "%", | |
| 1: "j" | |
| } | |
| } | |
| } | |
| }, | |
| 1: { | |
| 0: { | |
| 0: { | |
| 0: { | |
| 0: "<", | |
| 1: "g" | |
| }, | |
| 1: { | |
| 0: "Z", | |
| 1: "`" | |
| } | |
| }, | |
| 1: "f" | |
| }, | |
| 1: { | |
| 0: "r", | |
| 1: { | |
| 0: "n", | |
| 1: "a" | |
| } | |
| } | |
| } | |
| } | |
| }; | |
| /** | |
| * Applies a Caesar cipher shift to a single character. | |
| * @param {string} char The character to shift. | |
| * @param {number} shift The shift amount. | |
| * @returns {string} The shifted character. | |
| */ | |
| function caesarChar(char, shift) { | |
| const code = char.charCodeAt(); | |
| if(code >= 65 && code <= 90) { | |
| return String.fromCharCode((code - 65 + shift) % 26 + 65); | |
| } else if(code >= 97 && code <= 122) { | |
| return String.fromCharCode((code - 97 + shift) % 26 + 97); | |
| } else if(code === 32) { | |
| return String.fromCharCode(code + 1); | |
| } else if(code === 33) { | |
| return String.fromCharCode(code - 1); | |
| } else { | |
| return char; | |
| } | |
| } | |
| /** | |
| * Applies a Caesar cipher shift to a string. | |
| * @param {string} str The string to shift. | |
| * @param {number} shift The shift amount. | |
| * @returns {string} The shifted string. | |
| */ | |
| function caesarString(str, shift) { | |
| // 26 = English alphabet length | |
| return Array.from(str).map(function(ch) { return caesarChar(ch, shift % 26); }).join(""); | |
| } | |
| /** | |
| * Traverses a nested object using a string of keys, collecting string values. | |
| * @param {string} str The string of keys to traverse. | |
| * @param {object} obj The nested object to traverse. | |
| * @returns {string} The collected string values. | |
| */ | |
| function traverse(str, obj) { | |
| let result = ""; | |
| let current = obj; | |
| for(const ch of str) { | |
| current = current[ch]; | |
| if(typeof current === "string") { | |
| result += current; | |
| current = obj; | |
| } | |
| } | |
| return result; | |
| } | |
| /** | |
| * Decodes a base64 string to binary string. | |
| * @param {string} input The base64 encoded string. | |
| * @returns {string} The decoded binary string. | |
| */ | |
| function base64Decode(input) { | |
| return Buffer.from(input, 'base64').toString('binary'); | |
| // const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | |
| // let output = ""; | |
| // let i = 0; | |
| // input = input.replace(/=+$/, ""); | |
| // while(i < input.length) { | |
| // const a = chars.indexOf(input.charAt(i++)) << 18; | |
| // const b = chars.indexOf(input.charAt(i++)) << 12; | |
| // const c = chars.indexOf(input.charAt(i++)) << 6; | |
| // const d = chars.indexOf(input.charAt(i++)); | |
| // const bits = a | b | (c < 0 ? 0 : c) | (d < 0 ? 0 : d); | |
| // output += String.fromCharCode((bits >> 16) & 255); | |
| // if(c >= 0) output += String.fromCharCode((bits >> 8) & 255); | |
| // if(d >= 0) output += String.fromCharCode(bits & 255); | |
| // } | |
| // | |
| // return output; | |
| } | |
| /** | |
| * Decodes the encoded input string to a binary string of specified length. | |
| * @param {string} input The encoded input string. | |
| * @returns {string} The decoded binary string. | |
| */ | |
| function decode(input) { | |
| const len = base64Decode(input.substring(0, 4)); | |
| const bitLength = len.charCodeAt(0) << 8 | len.charCodeAt(1); | |
| const rest = base64Decode(input.substring(4)); | |
| let binary = ""; | |
| for(let i = 0; i < rest.length; i++) { | |
| let bits = rest.charCodeAt(i).toString(2); | |
| while(bits.length < 8) bits = "0" + bits; | |
| binary += bits; | |
| } | |
| return binary.slice(-bitLength); | |
| } | |
| const decodedString = traverse(decode(data.e), data.t); | |
| const splitParts = decodedString.split(/[@%<`~]/); | |
| /** | |
| * Gets the decoded and shifted string part by index. | |
| * @param {number} index The index of the part to decode and shift. | |
| * @returns {string} The decoded and shifted string. | |
| */ | |
| function getDecoded(index) { | |
| return caesarString(splitParts[index], 13); | |
| } | |
| console.log(getDecoded(0)); | |
| console.log(getDecoded(1)); | |
| console.log(getDecoded(2)); | |
| console.log(getDecoded(3)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment