Skip to content

Instantly share code, notes, and snippets.

@Saturate
Last active May 15, 2025 13:15
Show Gist options
  • Select an option

  • Save Saturate/129b4387babcfa0cb2e88bb7c0200a3f to your computer and use it in GitHub Desktop.

Select an option

Save Saturate/129b4387babcfa0cb2e88bb7c0200a3f to your computer and use it in GitHub Desktop.

Revisions

  1. Saturate revised this gist May 15, 2025. 1 changed file with 44 additions and 43 deletions.
    87 changes: 44 additions & 43 deletions encode-forsvarets-efterretningstjeneste.js
    Original file line number Diff line number Diff line change
    @@ -1,60 +1,61 @@
    (function () {
    function encodeToMorseNumbers(text) {
    const morseCodeMap = {
    "a": ".-",
    "b": "-...",
    "c": "-.-.",
    "d": "-..",
    "e": ".",
    "f": "..-.",
    "g": "--.",
    "h": "....",
    "i": "..",
    "j": ".---",
    "k": "-.-",
    "l": ".-..",
    "m": "--",
    "n": "-.",
    "o": "---",
    "p": ".--.",
    "q": "--.-",
    "r": ".-.",
    "s": "...",
    "t": "-",
    "u": "..-",
    "v": "...-",
    "w": ".--",
    "x": "-..-",
    "y": "-.--",
    "z": "--..",
    "æ": ".-.-",
    "ø": "---.",
    "å": ".--.-",
    "1": ".----",
    "2": "..---",
    "3": "...--",
    "4": "....-",
    "5": ".....",
    "6": "-....",
    "7": "--...",
    "8": "---..",
    "9": "----.",
    "0": "-----"
    a: ".-",
    b: "-...",
    c: "-.-.",
    d: "-..",
    e: ".",
    f: "..-.",
    g: "--.",
    h: "....",
    i: "..",
    j: ".---",
    k: "-.-",
    l: ".-..",
    m: "--",
    n: "-.",
    o: "---",
    p: ".--.",
    q: "--.-",
    r: ".-.",
    s: "...",
    t: "-",
    u: "..-",
    v: "...-",
    w: ".--",
    x: "-..-",
    y: "-.--",
    z: "--..",
    æ: ".-.-",
    ø: "---.",
    å: ".--.-",
    1: ".----",
    2: "..---",
    3: "...--",
    4: "....-",
    5: ".....",
    6: "-....",
    7: "--...",
    8: "---..",
    9: "----.",
    0: "-----",
    };

    const morseToNumbers = (morse) => {
    return morse
    .replace(/\./g, "0")
    .replace(/-/g, "1")
    .replace(/ /g, "/")
    .replace(/\/\//g, " ");
    .replace(/ /g, "//")
    .replace(/z/g, " / ")
    .replace(/\/ \/\/ \//g, " // ");
    };

    const morseCode = text
    .toLowerCase()
    .split("")
    .map((char) => morseCodeMap[char] || "")
    .join(" ");
    .map((char) => morseCodeMap[char] || char)
    .join("z");

    return morseToNumbers(morseCode);
    }
  2. Saturate revised this gist May 15, 2025. 1 changed file with 63 additions and 0 deletions.
    63 changes: 63 additions & 0 deletions encode-forsvarets-efterretningstjeneste.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    (function () {
    function encodeToMorseNumbers(text) {
    const morseCodeMap = {
    "a": ".-",
    "b": "-...",
    "c": "-.-.",
    "d": "-..",
    "e": ".",
    "f": "..-.",
    "g": "--.",
    "h": "....",
    "i": "..",
    "j": ".---",
    "k": "-.-",
    "l": ".-..",
    "m": "--",
    "n": "-.",
    "o": "---",
    "p": ".--.",
    "q": "--.-",
    "r": ".-.",
    "s": "...",
    "t": "-",
    "u": "..-",
    "v": "...-",
    "w": ".--",
    "x": "-..-",
    "y": "-.--",
    "z": "--..",
    "æ": ".-.-",
    "ø": "---.",
    "å": ".--.-",
    "1": ".----",
    "2": "..---",
    "3": "...--",
    "4": "....-",
    "5": ".....",
    "6": "-....",
    "7": "--...",
    "8": "---..",
    "9": "----.",
    "0": "-----"
    };

    const morseToNumbers = (morse) => {
    return morse
    .replace(/\./g, "0")
    .replace(/-/g, "1")
    .replace(/ /g, "/")
    .replace(/\/\//g, " ");
    };

    const morseCode = text
    .toLowerCase()
    .split("")
    .map((char) => morseCodeMap[char] || "")
    .join(" ");

    return morseToNumbers(morseCode);
    }

    console.log(encodeToMorseNumbers("hello world"));
    })();
  3. Saturate revised this gist May 15, 2025. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions decode-forsvarets-efterretningstjeneste.js
    Original file line number Diff line number Diff line change
    @@ -27,6 +27,9 @@
    "-..-": "x",
    "-.--": "y",
    "--..": "z",
    ".-.-": "æ",
    "---.": "ø",
    ".--.-": "å",
    ".----": "1",
    "..---": "2",
    "...--": "3",
  4. Saturate created this gist May 15, 2025.
    68 changes: 68 additions & 0 deletions decode-forsvarets-efterretningstjeneste.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    (function () {
    function decodeMorse(morseCode) {
    const r = {
    ".-": "a",
    "-...": "b",
    "-.-.": "c",
    "-..": "d",
    ".": "e",
    "..-.": "f",
    "--.": "g",
    "....": "h",
    "..": "i",
    ".---": "j",
    "-.-": "k",
    ".-..": "l",
    "--": "m",
    "-.": "n",
    "---": "o",
    ".--.": "p",
    "--.-": "q",
    ".-.": "r",
    "...": "s",
    "-": "t",
    "..-": "u",
    "...-": "v",
    ".--": "w",
    "-..-": "x",
    "-.--": "y",
    "--..": "z",
    ".----": "1",
    "..---": "2",
    "...--": "3",
    "....-": "4",
    ".....": "5",
    "-....": "6",
    "--...": "7",
    "---..": "8",
    "----.": "9",
    "-----": "0",
    };

    return morseCode
    .split(" ")
    .map((a) =>
    a
    .split(" ")
    .map((b) => r[b])
    .join("")
    )
    .join(" ");
    }

    function convertToMorse(input) {
    return input
    .replace(/1/g, "-")
    .replace(/0/g, ".")
    .replace(/\/\//g, " ")
    .replace(/\//g, "");
    }

    console.log(
    decodeMorse(
    convertToMorse(
    "0001 / 00 / 100 / 0 / 10 // 111 / 110 // 000 / 00 / 101 / 101 / 0 / 010 / 0000 / 0 / 100"
    )
    )
    );
    })();