How to decode Leet Speak (where numbers resemble letters (7->T, 1->I, 5->S, 3 -> E)) in TypeScript

2 Answers

0 votes
// 7H15 M3554G3 is written in leet speak, where numbers resemble letters.
// place each leetspeak character with its matching letter
// (7 -> T, 1 -> I, 5 -> S, 3 -> E) and build a new string
// 7H15 -> THIS | M3554G3 -> MESSAGE

// Your brain can interpret distorted or number‑substituted letters
// surprisingly well because it recognizes the overall word
// shapes and patterns, not just individual characters.

// ------------------------------------------------------------
// Convert a single leet character into a normal alphabet letter
// ------------------------------------------------------------
function decodeChar(c: string): string {
    const table: Record<string, string> = {
        "7": "T",
        "1": "I",
        "5": "S",
        "3": "E",
        "4": "A",
        "0": "O"
    };

    return table[c] ?? c;  // keep letters like H, M, G, etc.
}

// ------------------------------------------------------------
// Convert an entire string from leet speak to normal text
// ------------------------------------------------------------
function decodeLeetSpeak(s: string): string {
    return [...s].map(decodeChar).join("");
}

// ------------------------------------------------------------
// Test lines provided by the user
// ------------------------------------------------------------
const lines: string[] = [
    "7H15 M3554G3",
    "53RV35 7O PR0V3",
    "H0W 0UR M1ND5 C4N",
    "D0 4M4Z1NG 7H1NG5!",
    "1MPR3551V3 7H1NG5!",
    "1N 7H3 B3G1NN1NG",
    "17 WA5 H4RD BU7",
    "N0W, Y0UR M1ND 1S",
    "R34D1NG 17",
    "4U70M471C4LLY."
];

// Decode and print each line
for (const line of lines) {
    console.log(decodeLeetSpeak(line));
}


/*
run:

THIS MESSAGE
SERVES TO PROVE
HOW OUR MINDS CAN
DO AMAZING THINGS!
IMPRESSIVE THINGS!
IN THE BEGINNING
IT WAS HARD BUT
NOW, YOUR MIND IS
READING IT
AUTOMATICALLY.

*/

 



answered 5 hours ago by avibootz
edited 4 hours ago by avibootz
0 votes
// 7H15 M3554G3 is written in leet speak, where numbers resemble letters.
// place each leetspeak character with its matching letter
// (7 -> T, 1 -> I, 5 -> S, 3 -> E) and build a new string
// 7H15 -> THIS | M3554G3 -> MESSAGE

// Your brain can interpret distorted or number‑substituted letters
// surprisingly well because it recognizes the overall word
// shapes and patterns, not just individual characters.

// ------------------------------------------------------------
// Convert an entire string from leet speak to normal text
// ------------------------------------------------------------
function decodeLeetSpeak(s: string): string {
    const MAP = { "7":"T", "1":"I", "5":"S", "3":"E", "4":"A", "0":"O" } as const;
    
    const decodeLeet = (s: string) => s.replace(/[715340]/g, c => MAP[c as keyof typeof MAP]);
    
    return decodeLeet(s);
}

// ------------------------------------------------------------
// Test lines provided by the user
// ------------------------------------------------------------
const lines: string[] = [
    "7H15 M3554G3",
    "53RV35 7O PR0V3",
    "H0W 0UR M1ND5 C4N",
    "D0 4M4Z1NG 7H1NG5!",
    "1MPR3551V3 7H1NG5!",
    "1N 7H3 B3G1NN1NG",
    "17 WA5 H4RD BU7",
    "N0W, Y0UR M1ND 1S",
    "R34D1NG 17",
    "4U70M471C4LLY."
];

// Decode and print each line
for (const line of lines) {
    console.log(decodeLeetSpeak(line));
}


/*
run:

THIS MESSAGE
SERVES TO PROVE
HOW OUR MINDS CAN
DO AMAZING THINGS!
IMPRESSIVE THINGS!
IN THE BEGINNING
IT WAS HARD BUT
NOW, YOUR MIND IS
READING IT
AUTOMATICALLY.

*/

 



answered 5 hours ago by avibootz
edited 4 hours ago by avibootz
...