30 private mapping: Record<string, string>;
35 private inverse: Record<string, string>;
46 const sanitizedMap = this.sanitize(mapAlphabet);
48 if (sanitizedMap.length !== 26) {
49 throw new Error(
"mapAlphabet must have 26 letters");
55 for (let i = 0; i < 26; i++) {
68 encode(plainText:
string =
""): string {
71 .map(c => this.mapping[c.toUpperCase()] ?? c)
82 decode(cipherText:
string =
""):
string {
85 .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="")
Constructor for Monoalphabetic cipher.
readonly CipherName
Identifier name for this cipher.
export const Record< string,(...args:any[])=> string