Asper Header  1.0.14
The header injector extension
Loading...
Searching...
No Matches
doubleTransposition.ts
Go to the documentation of this file.
1
12import { BaseCipher } from "../base/baseCipher";
13import { ColumnarCipher } from "./columnar";
14
26 readonly CipherName = "DoubleTransposition";
27
33 super();
34 }
35
45 encode(plainText: string = "", key1: string = "", key2?: string): string {
46 const firstKey = key1;
47 const secondKey = key2 ?? key1;
48
49 const columnar1 = new ColumnarCipher();
50 const columnar2 = new ColumnarCipher();
51
52 const firstPass = columnar1.encode(plainText, firstKey);
53 const secondPass = columnar2.encode(firstPass, secondKey);
54
55 return secondPass;
56 }
57
67 decode(cipherText: string = "", key1: string = "", key2?: string): string {
68 const firstKey = key1;
69 const secondKey = key2 ?? key1;
70
71 const columnar1 = new ColumnarCipher();
72 const columnar2 = new ColumnarCipher();
73
74 const intermediate = columnar2.decode(cipherText, secondKey);
75 const finalText = columnar1.decode(intermediate, firstKey);
76
77 return finalText;
78 }
79}
Abstract base class providing common functionality for cipher implementations.
Definition baseCipher.ts:18
Implementation of the Columnar Transposition cipher.
Definition columnar.ts:21
Implementation of double columnar transposition cipher.
constructor()
Constructor for Double Transposition cipher.
readonly CipherName
Identifier name for this cipher.
ColumnarCipher
Definition index.ts:19
export const Record< string,(...args:any[])=> string