Last active
May 15, 2025 13:15
-
-
Save Saturate/129b4387babcfa0cb2e88bb7c0200a3f to your computer and use it in GitHub Desktop.
Revisions
-
Saturate revised this gist
May 15, 2025 . 1 changed file with 44 additions and 43 deletions.There are no files selected for viewing
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 charactersOriginal 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: "-----", }; const morseToNumbers = (morse) => { return morse .replace(/\./g, "0") .replace(/-/g, "1") .replace(/ /g, "//") .replace(/z/g, " / ") .replace(/\/ \/\/ \//g, " // "); }; const morseCode = text .toLowerCase() .split("") .map((char) => morseCodeMap[char] || char) .join("z"); return morseToNumbers(morseCode); } -
Saturate revised this gist
May 15, 2025 . 1 changed file with 63 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal 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")); })(); -
Saturate revised this gist
May 15, 2025 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,6 +27,9 @@ "-..-": "x", "-.--": "y", "--..": "z", ".-.-": "æ", "---.": "ø", ".--.-": "å", ".----": "1", "..---": "2", "...--": "3", -
Saturate created this gist
May 15, 2025 .There are no files selected for viewing
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 charactersOriginal 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" ) ) ); })();