Skip to content

Instantly share code, notes, and snippets.

@jonathas
Created November 4, 2021 11:27
Show Gist options
  • Select an option

  • Save jonathas/f31d2b1ac97b84b7a8d949a3a5b608f5 to your computer and use it in GitHub Desktop.

Select an option

Save jonathas/f31d2b1ac97b84b7a8d949a3a5b608f5 to your computer and use it in GitHub Desktop.
Caesar Cipher
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