Asper Header  1.0.14
The header injector extension
Loading...
Searching...
No Matches
atBash.ts
Go to the documentation of this file.
1
12import { BaseCipher } from "../base/baseCipher";
13
21export class AtbashCipher extends BaseCipher {
25 readonly CipherName = "Atbash";
26
31 private readonly map: Record<string, string>;
32
39 super();
40 this.map = {};
41
42 const alphabet = BaseCipher.ALPHABET;
43 for (let i = 0; i < alphabet.length; i++) {
44 this.map[alphabet[i]] = alphabet[alphabet.length - 1 - i];
45 }
46 }
47
55 encode(plainText: string = ""): string {
56 return plainText
57 .split("")
58 .map(ch => this.map[ch.toUpperCase()] ?? ch)
59 .join("");
60 }
61
69 decode(cipherText: string = ""): string {
70 // Atbash is symmetric — same as encode
71 return this.encode(cipherText);
72 }
73}
Implementation of the Atbash substitution cipher.
Definition atBash.ts:21
constructor()
Constructor for Atbash cipher.
Definition atBash.ts:38
readonly CipherName
Identifier name for this cipher.
Definition atBash.ts:25
Abstract base class providing common functionality for cipher implementations.
Definition baseCipher.ts:18
static readonly ALPHABET
Standard English alphabet for cipher operations.
Definition baseCipher.ts:44
export const Record< string,(...args:any[])=> string