Skip to content

Commit 937134b

Browse files
committed
fix caesar_cipher
1 parent f966b9a commit 937134b

File tree

1 file changed

+4
-4
lines changed
  • algorithm/cryptography/caesar_cipher/basic

1 file changed

+4
-4
lines changed

algorithm/cryptography/caesar_cipher/basic/code.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function getNextChar(currChar, direction) {
1010
var pos = alphabetMap[currChar];
1111
var nextPos = direction === 'up' ? getPosUp(pos) : getPosDown(pos);
1212
var nextChar = alphabet.charAt(nextPos);
13-
13+
1414
logger._print(currChar + ' -> ' + nextChar);
1515
return nextChar;
1616
}
@@ -21,19 +21,19 @@ function cipher(str, rotation, direction, cipherTracer) {
2121
for (var i = 0; i < str.length; i++) {
2222

2323
cipherTracer._wait();
24-
24+
2525
var currChar = str.charAt(i);
2626
var r = rotation;
2727

2828
logger._print('Rotating ' + currChar + ' ' + direction + ' ' + rotation + ' times');
2929
cipherTracer._notify(i)._wait();
3030

3131
// perform given amount of rotations in the given direction
32-
while (--r > 0) {
32+
while (r-- > 0) {
3333
currChar = getNextChar(currChar, direction);
3434
cipherTracer._notify(i, currChar)._wait();
3535
}
36-
36+
3737
str = str.substring(0, i) + currChar + str.substring(i + 1);
3838
logger._print('Current result: ' + str);
3939
}

0 commit comments

Comments
 (0)