Skip to content

Commit 5d5527c

Browse files
committed
Encrypt strings with characters not in alphabet
1 parent 5db921c commit 5d5527c

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

algorithm/cryptography/caesar_cipher/basic/code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function cipher(str, rotation, direction, cipherTracer) {
2323
cipherTracer._wait();
2424

2525
var currChar = str.charAt(i);
26-
if ( currChar !== ' ' ) { // do not encrpt/decrypt spaces
26+
if (typeof alphabetMap[currChar] === 'number') { // don't encrpt/decrypt characters not in alphabetMap
2727
var r = rotation;
2828

2929
logger._print('Rotating ' + currChar + ' ' + direction + ' ' + rotation + ' times');
@@ -35,7 +35,7 @@ function cipher(str, rotation, direction, cipherTracer) {
3535
cipherTracer._notify(i, currChar)._wait();
3636
}
3737
} else {
38-
logger._print('Ignore space');
38+
logger._print('Ignore this character');
3939
}
4040
str = str.substring(0, i) + currChar + str.substring(i + 1);
4141
logger._print('Current result: ' + str);

algorithm/cryptography/caesar_cipher/basic/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var string = 'secret msg';
1+
var string = 'hello! how are you doing?';
22
var rotation = 5;
33
var alphabet = 'abcdefghijklmnopqrstuvwxyz';
44
// create a map of char -> position to improve run time

0 commit comments

Comments
 (0)