Created
November 4, 2021 11:27
-
-
Save jonathas/f31d2b1ac97b84b7a8d949a3a5b608f5 to your computer and use it in GitHub Desktop.
Caesar Cipher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CaesarCipher { | |
| private characters = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
| private shift = 4; | |
| public decrypt(value: string): string { | |
| return value.toString().split("") | |
| .map(v => this.shiftNumber(Number(v))).join(""); | |
| } | |
| private shiftNumber(x: number): number { | |
| let char = this.characters[this.characters.indexOf(x)]-this.shift; | |
| if (char < 0) { | |
| char = this.characters.slice(char)[0]; | |
| } | |
| return char; | |
| } | |
| } | |
| export default CaesarCipher; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment