Asper Header  1.0.14
The header injector extension
Loading...
Searching...
No Matches
pigpen.ts
Go to the documentation of this file.
1
12import { BaseCipher } from "../base/baseCipher";
13
21export class PigpenCipher extends BaseCipher {
25 readonly CipherName = "Pigpen";
26
30 private map: Record<string, string> = {};
31
35 private inv: Record<string, string> = {};
36
43 super();
44
45 // define simple textual mapping for Pigpen (non-graphical)
46 const symbols = [
47 '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
48 ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '_'
49 ];
50
51 for (let i = 0; i < 26; i++) {
52 this.map[PigpenCipher.ALPHABET[i]] = symbols[i];
53 this.inv[symbols[i]] = PigpenCipher.ALPHABET[i];
54 }
55 }
56
64 encode(plainText: string = ""): string {
65 return plainText
66 .split('')
67 .map(c => this.map[c.toUpperCase()] ?? c)
68 .join('');
69 }
70
78 decode(cipherText: string = ""): string {
79 return cipherText
80 .split('')
81 .map(c => this.inv[c] ?? c)
82 .join('');
83 }
84}
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
Implementation of the Pigpen (Freemason's) substitution cipher.
Definition pigpen.ts:21
constructor()
Constructor for Pigpen cipher.
Definition pigpen.ts:42
readonly CipherName
Identifier name for this cipher.
Definition pigpen.ts:25
export const Record< string,(...args:any[])=> string