Caeser cipher (#517) · polesye/javascript-algorithms@bd7475e · GitHub
Skip to content

Commit bd7475e

Browse files
authored
Caeser cipher (trekhleb#517)
* added ceaserCipher algorithm * added ceaserCipher algorithm * fixed a typo
1 parent e54a3df commit bd7475e

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import caeserCipher from '../caeserCipher';
2+
3+
describe('caeserCipher', () => {
4+
it('should subtitute each character by shifting up the alphabet by a given integer', () => {
5+
6+
7+
expect(caeserCipher('abcd', 1)).toBe('bcde');
8+
});
9+
10+
11+
it('should wrap back to the beginning of the alphabet if it shifts more than the 26 english alphabets', () => {
12+
13+
14+
expect(caeserCipher('xyz', 1)).toBe('yza');
15+
});
16+
it('should only shift letters and ignore non-alphabetic characters', () => {
17+
18+
expect(caeserCipher('gurer ner 9 qbtf!', 13)).toBe('there are 9 dogs!');
19+
});
20+
21+
it('should ignore case sensitivity', () => {
22+
23+
expect(caeserCipher('ABCD', 13)).toBe('bcde');
24+
});
25+
26+
27+
})
Lines changed: 30 additions & 0 deletions

0 commit comments

Comments
 (0)