30 private mapping: Record<string, string>;
35 private inverse: Record<string, string>;
44 constructor(mapAlphabet:
string =
"QWERTYUIOPASDFGHJKLZXCVBNM") {
47 const sanitizedMap = this.sanitize(mapAlphabet);
49 if (sanitizedMap.length !== 26) {
50 throw new Error(
"mapAlphabet must have 26 letters");
56 for (let i = 0; i < 26; i++) {
69 encode(plainText:
string =
""): string {
72 .map(c => this.mapping[c.toUpperCase()] ?? c)
83 decode(cipherText:
string =
""):
string {
86 .map(c => this.inverse[c.toUpperCase()] ?? c)
Abstract base class providing common functionality for cipher implementations.
static readonly ALPHABET
Standard English alphabet for cipher operations.
Implementation of a customizable monoalphabetic substitution cipher.
constructor(mapAlphabet:string="QWERTYUIOPASDFGHJKLZXCVBNM")
Constructor for Monoalphabetic cipher.
readonly CipherName
Identifier name for this cipher.
export const export const string[]