forked from rudimuc/obsidian-coder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRot13.ts
51 lines (41 loc) · 1.54 KB
/
Rot13.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Coder } from "./Coder";
export class Rot13Encoder implements Coder {
from:string;
to: string;
constructor() {
this.from = "text";
this.to = "rot13";
}
rot13(txt:string) {
return txt.replace(/[a-z]/gi, c =>
"NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
[ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".indexOf(c) ] );
}
transform (text:string) : string {
return this.rot13(text);
}
checkInput(text: string): boolean {
// For now, we assume that all text is valid. We will only encode A-Z and a-z. The rest will be left as is.
return true;
}
}
export class Rot13Decoder implements Coder {
from:string;
to: string;
constructor() {
this.from = "rot13";
this.to = "text";
}
derot13(txt:string) {
return txt.replace(/[a-z]/gi, c =>
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
[ "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm".indexOf(c) ] );
}
transform (text:string) : string {
return this.derot13(text);
}
checkInput(text: string): boolean {
// For now, we assume that all text is valid. We will only encode A-Z and a-z. The rest will be left as is.
return true;
}
}