Asper Header  1.0.14
The header injector extension
Loading...
Searching...
No Matches
morseBasic.ts
Go to the documentation of this file.
1
12import { BaseCipher } from "../base/baseCipher";
13
21export class MorseBasicCipher extends BaseCipher {
25 readonly CipherName = "MorseBasic";
26
31 private map: Record<string, string> = {
32 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..',
33 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....',
34 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
35 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.',
36 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-',
37 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
38 'Y': '-.--', 'Z': '--..',
39 '0': '-----', '1': '.----', '2': '..---', '3': '...--',
40 '4': '....-', '5': '.....', '6': '-....', '7': '--...',
41 '8': '---..', '9': '----.'
42 };
43
51 encode(plainText: string = ""): string {
52 return plainText
53 .split("")
54 .map(c => this.map[c.toUpperCase()] ?? c)
55 .join(" ");
56 }
57
65 decode(cipherText: string = ""): string {
66 const inverseMap: Record<string, string> = {};
67 for (const key in this.map) {
68 inverseMap[this.map[key]] = key;
69 }
70
71 return cipherText
72 .split(" ")
73 .map(code => inverseMap[code] ?? code)
74 .join("");
75 }
76}
Abstract base class providing common functionality for cipher implementations.
Definition baseCipher.ts:18
Implementation of Morse code encoding and decoding.
Definition morseBasic.ts:21
readonly CipherName
Identifier name for this cipher.
Definition morseBasic.ts:25
export const Record< string,(...args:any[])=> string