From c99c9515f7592c9cb3bb996e2374fdec3534b1d4 Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Wed, 9 Oct 2019 00:24:56 +0530 Subject: [PATCH 01/12] basic caesarCipher and a single test for trial. --- .../caeser_cipher/caesarCipher.test.js | 19 ++++++++ src/_Classics_/caeser_cipher/caeserCipher.js | 47 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/_Classics_/caeser_cipher/caesarCipher.test.js create mode 100644 src/_Classics_/caeser_cipher/caeserCipher.js diff --git a/src/_Classics_/caeser_cipher/caesarCipher.test.js b/src/_Classics_/caeser_cipher/caesarCipher.test.js new file mode 100644 index 00000000..dffb7b13 --- /dev/null +++ b/src/_Classics_/caeser_cipher/caesarCipher.test.js @@ -0,0 +1,19 @@ +/* eslint-disable linebreak-style */ +/* eslint-disable no-else-return */ +const caesarCipher = require('./caeserCipher'); + +const compareString = (str1, str2) => { + if (str1 === str2) { + return true; + } else { + return false; + } +}; + +describe('Caesar Cipher tests', () => { + it('Shift not passed', () => { + const ocString = 'Hello World'; + const enciphered = caesarCipher(ocString); + expect(compareString(ocString, enciphered)).tobe(true); + }); +}); diff --git a/src/_Classics_/caeser_cipher/caeserCipher.js b/src/_Classics_/caeser_cipher/caeserCipher.js new file mode 100644 index 00000000..43e75366 --- /dev/null +++ b/src/_Classics_/caeser_cipher/caeserCipher.js @@ -0,0 +1,47 @@ +/** + * @param {String} toEncipher + * @param {Number} shift +*/ +function caesarCipher(toEncipher, shift = 0) { + // If required for very strict shift checking then remove '=0' + if (typeof (Number(shift)) !== 'number') { + return Error('Invalid Shift Provided') + } else { + shift = Number(shift); + } + + if(typeof(toEncipher) === 'string' || typeof(toEncipher) === 'number') { + toEncipher = String(toEncipher); + } else { + return Error('Invalid string provided'); + } + + // These are the valid entries aacepted, you can change it according to requirements + const validEntries = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; + + shift %= validEntries.length; + + let output = ''; + for (let char of toEncipher) { + if (char === ' ') { + output += ' '; + continue; + //------- If you donot want to accept invalid entries then uncomment below block + /* + ======================================================================================================== + } else if (validEntries.indexOf(char) === -1) {return Error ('invalid character' + char)} + ======================================================================================================== + and comment out the below block + */ + //======================================================================================================= + } else if (validEntries.indexOf(char) === -1) { + output += char; + continue; + } + //======================================================================================================= + output += (validEntries.indexOf(char) + shift <= validEntries.length) ? validEntries[validEntries.indexOf(char) + shift] : validEntries[(validEntries.indexOf(char) + shift) % validEntries.length]; + } + return output; +} + +module.exports = caesarCipher; \ No newline at end of file From 7591809696bbc393d14f5a249c6c1fd8e4feabf1 Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Wed, 9 Oct 2019 00:27:54 +0530 Subject: [PATCH 02/12] fixed 'toBe' --- src/_Classics_/caeser_cipher/caesarCipher.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_Classics_/caeser_cipher/caesarCipher.test.js b/src/_Classics_/caeser_cipher/caesarCipher.test.js index dffb7b13..378895c5 100644 --- a/src/_Classics_/caeser_cipher/caesarCipher.test.js +++ b/src/_Classics_/caeser_cipher/caesarCipher.test.js @@ -14,6 +14,6 @@ describe('Caesar Cipher tests', () => { it('Shift not passed', () => { const ocString = 'Hello World'; const enciphered = caesarCipher(ocString); - expect(compareString(ocString, enciphered)).tobe(true); + expect(compareString(ocString, enciphered)).toBe(true); }); }); From f6b29cc69eb9420dd239ab54ca01a6bb2fb49a05 Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Wed, 9 Oct 2019 01:22:01 +0530 Subject: [PATCH 03/12] some condition changes --- src/_Classics_/caeser_cipher/caeserCipher.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_Classics_/caeser_cipher/caeserCipher.js b/src/_Classics_/caeser_cipher/caeserCipher.js index 43e75366..3c212c8b 100644 --- a/src/_Classics_/caeser_cipher/caeserCipher.js +++ b/src/_Classics_/caeser_cipher/caeserCipher.js @@ -4,16 +4,16 @@ */ function caesarCipher(toEncipher, shift = 0) { // If required for very strict shift checking then remove '=0' - if (typeof (Number(shift)) !== 'number') { - return Error('Invalid Shift Provided') + if (typeof (Number(shift)) !== 'number' && (shift !== NaN || shift !== 'NaN' || Number(shift) !== NaN )) { + throw Error('Invalid Shift Provided') } else { shift = Number(shift); } - if(typeof(toEncipher) === 'string' || typeof(toEncipher) === 'number') { + if(typeof(toEncipher) === 'string' || (typeof(toEncipher) === 'number' && toEncipher !== NaN)) { toEncipher = String(toEncipher); } else { - return Error('Invalid string provided'); + throw Error('Invalid string provided'); } // These are the valid entries aacepted, you can change it according to requirements From 88646e365e716123e9ff365b4e635d3dfa774e40 Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Wed, 9 Oct 2019 01:25:52 +0530 Subject: [PATCH 04/12] condition for shift reconstructed --- src/_Classics_/caeser_cipher/caeserCipher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_Classics_/caeser_cipher/caeserCipher.js b/src/_Classics_/caeser_cipher/caeserCipher.js index 3c212c8b..b94a3c6b 100644 --- a/src/_Classics_/caeser_cipher/caeserCipher.js +++ b/src/_Classics_/caeser_cipher/caeserCipher.js @@ -4,7 +4,7 @@ */ function caesarCipher(toEncipher, shift = 0) { // If required for very strict shift checking then remove '=0' - if (typeof (Number(shift)) !== 'number' && (shift !== NaN || shift !== 'NaN' || Number(shift) !== NaN )) { + if (Number(shift) === NaN) { throw Error('Invalid Shift Provided') } else { shift = Number(shift); From cdfa983be7ff8e1857602702b4428c1dfbcaf5a6 Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Wed, 9 Oct 2019 01:26:05 +0530 Subject: [PATCH 05/12] tests added --- .../caeser_cipher/caesarCipher.test.js | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/_Classics_/caeser_cipher/caesarCipher.test.js b/src/_Classics_/caeser_cipher/caesarCipher.test.js index 378895c5..093e49bc 100644 --- a/src/_Classics_/caeser_cipher/caesarCipher.test.js +++ b/src/_Classics_/caeser_cipher/caesarCipher.test.js @@ -13,7 +13,55 @@ const compareString = (str1, str2) => { describe('Caesar Cipher tests', () => { it('Shift not passed', () => { const ocString = 'Hello World'; - const enciphered = caesarCipher(ocString); - expect(compareString(ocString, enciphered)).toBe(true); + const enCiphered = caesarCipher(ocString); + expect(compareString(ocString, enCiphered)).toBe(true); + }); + + it('Encipher equals decipher', () => { + const ocString = 'Hello World'; + const enCiphered = caesarCipher(ocString, 1); + const deCiphered = caesarCipher(enCiphered, -1); + expect(compareString(ocString, deCiphered)).toBe(true); + }); + + it('Shift lower than string length works', () => { + const ocString = 'Hello World'; + const enCiphered = caesarCipher(ocString, 1); + const idealResult = 'Ifmmp Xpsme'; + expect(compareString(enCiphered, idealResult)).toBe(true); + }); + + it('Shift Higher than string length works', () => { + const ocString = 'Hello World'; + const enCiphered = caesarCipher(ocString, 63); + const idealResult = caesarCipher(ocString, 1); + expect(compareString(enCiphered, idealResult)).toBe(true); + }); + + it('Negative shift Works', () => { + const ocString = 'Ifmmp Xpsme'; + const enCiphered = caesarCipher(ocString, -1); + const idealResult = 'Hello World'; + expect(compareString(enCiphered, idealResult)).toBe(true); + }); + + it('Shift is a numerical string', () => { + const ocString = 'Hello World'; + const enCiphered = caesarCipher(ocString, '1'); + const idealResult = 'Ifmmp Xpsme'; + expect(compareString(enCiphered, idealResult)).toBe(true); + // toThrowError + }); + + it('Shift is not a numbered string', () => { + expect(caesarCipher('Hello World', 'abc')).toThrowError('Invalid Shift Provided'); + }); + + it('toEncipher is NaN', () => { + expect(caesarCipher(NaN, 1)).toThrowError('Invalid string provided'); + }); + + it('toEncipher is undefined', () => { + expect(caesarCipher(undefined, 1)).toThrowError('Invalid string provided'); }); }); From b685575194bb2eba167f397eb8ed4933ca033d9b Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Wed, 9 Oct 2019 01:31:08 +0530 Subject: [PATCH 06/12] trying to resolve throw and return --- src/_Classics_/caeser_cipher/caeserCipher.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/_Classics_/caeser_cipher/caeserCipher.js b/src/_Classics_/caeser_cipher/caeserCipher.js index b94a3c6b..e25f8350 100644 --- a/src/_Classics_/caeser_cipher/caeserCipher.js +++ b/src/_Classics_/caeser_cipher/caeserCipher.js @@ -1,11 +1,7 @@ -/** - * @param {String} toEncipher - * @param {Number} shift -*/ function caesarCipher(toEncipher, shift = 0) { // If required for very strict shift checking then remove '=0' if (Number(shift) === NaN) { - throw Error('Invalid Shift Provided') + return Error('Invalid Shift Provided') } else { shift = Number(shift); } @@ -13,7 +9,7 @@ function caesarCipher(toEncipher, shift = 0) { if(typeof(toEncipher) === 'string' || (typeof(toEncipher) === 'number' && toEncipher !== NaN)) { toEncipher = String(toEncipher); } else { - throw Error('Invalid string provided'); + return Error('Invalid string provided'); } // These are the valid entries aacepted, you can change it according to requirements From 9759a8121aebe61a04e003720c21fca80a0314ba Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Wed, 9 Oct 2019 01:57:19 +0530 Subject: [PATCH 07/12] little bug resolved. Test bug resolved too --- src/_Classics_/caeser_cipher/caesarCipher.test.js | 15 ++++++++++++--- src/_Classics_/caeser_cipher/caeserCipher.js | 8 ++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/_Classics_/caeser_cipher/caesarCipher.test.js b/src/_Classics_/caeser_cipher/caesarCipher.test.js index 093e49bc..e8d43042 100644 --- a/src/_Classics_/caeser_cipher/caesarCipher.test.js +++ b/src/_Classics_/caeser_cipher/caesarCipher.test.js @@ -54,14 +54,23 @@ describe('Caesar Cipher tests', () => { }); it('Shift is not a numbered string', () => { - expect(caesarCipher('Hello World', 'abc')).toThrowError('Invalid Shift Provided'); + function test() { + caesarCipher('Hello World', 'abc'); + } + expect(test).toThrow('Invalid Shift Provided'); }); it('toEncipher is NaN', () => { - expect(caesarCipher(NaN, 1)).toThrowError('Invalid string provided'); + function test() { + caesarCipher(NaN, 1); + } + expect(test).toThrowError('Invalid string provided'); }); it('toEncipher is undefined', () => { - expect(caesarCipher(undefined, 1)).toThrowError('Invalid string provided'); + function test() { + caesarCipher(undefined, 1); + } + expect(test).toThrowError('Invalid string provided'); }); }); diff --git a/src/_Classics_/caeser_cipher/caeserCipher.js b/src/_Classics_/caeser_cipher/caeserCipher.js index e25f8350..81000488 100644 --- a/src/_Classics_/caeser_cipher/caeserCipher.js +++ b/src/_Classics_/caeser_cipher/caeserCipher.js @@ -1,15 +1,15 @@ function caesarCipher(toEncipher, shift = 0) { // If required for very strict shift checking then remove '=0' - if (Number(shift) === NaN) { - return Error('Invalid Shift Provided') + if (Number.isNaN(Number(shift)) === true) { + throw new Error('Invalid Shift Provided') } else { shift = Number(shift); } - if(typeof(toEncipher) === 'string' || (typeof(toEncipher) === 'number' && toEncipher !== NaN)) { + if(typeof(toEncipher) === 'string' || (typeof(toEncipher) === 'number' && Number.isNaN(toEncipher) === false)) { toEncipher = String(toEncipher); } else { - return Error('Invalid string provided'); + throw new Error('Invalid string provided'); } // These are the valid entries aacepted, you can change it according to requirements From 2a2cdbc2d2035731e5f988e1b03e2d841305dc80 Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Wed, 9 Oct 2019 02:01:06 +0530 Subject: [PATCH 08/12] folder Renamed --- .../{caeser_cipher => caesar_cipher}/caesarCipher.test.js | 0 src/_Classics_/{caeser_cipher => caesar_cipher}/caeserCipher.js | 0 src/_Classics_/{caeser_cipher => caesar_cipher}/index.js | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/_Classics_/{caeser_cipher => caesar_cipher}/caesarCipher.test.js (100%) rename src/_Classics_/{caeser_cipher => caesar_cipher}/caeserCipher.js (100%) rename src/_Classics_/{caeser_cipher => caesar_cipher}/index.js (100%) diff --git a/src/_Classics_/caeser_cipher/caesarCipher.test.js b/src/_Classics_/caesar_cipher/caesarCipher.test.js similarity index 100% rename from src/_Classics_/caeser_cipher/caesarCipher.test.js rename to src/_Classics_/caesar_cipher/caesarCipher.test.js diff --git a/src/_Classics_/caeser_cipher/caeserCipher.js b/src/_Classics_/caesar_cipher/caeserCipher.js similarity index 100% rename from src/_Classics_/caeser_cipher/caeserCipher.js rename to src/_Classics_/caesar_cipher/caeserCipher.js diff --git a/src/_Classics_/caeser_cipher/index.js b/src/_Classics_/caesar_cipher/index.js similarity index 100% rename from src/_Classics_/caeser_cipher/index.js rename to src/_Classics_/caesar_cipher/index.js From e8e30b7747c570d8745d050157c35e7d8b0e6158 Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Thu, 10 Oct 2019 01:45:22 +0530 Subject: [PATCH 09/12] index.js removed and indentations fixed to eslint. --- src/_Classics_/caesar_cipher/caeserCipher.js | 61 ++++++++++---------- src/_Classics_/caesar_cipher/index.js | 61 -------------------- 2 files changed, 32 insertions(+), 90 deletions(-) delete mode 100644 src/_Classics_/caesar_cipher/index.js diff --git a/src/_Classics_/caesar_cipher/caeserCipher.js b/src/_Classics_/caesar_cipher/caeserCipher.js index 81000488..d2a9a9d8 100644 --- a/src/_Classics_/caesar_cipher/caeserCipher.js +++ b/src/_Classics_/caesar_cipher/caeserCipher.js @@ -1,43 +1,46 @@ +/** + * Most simplest encryption scheme. Read more: [http://practicalcryptography.com/ciphers/caesar-cipher/] + **/ function caesarCipher(toEncipher, shift = 0) { - // If required for very strict shift checking then remove '=0' - if (Number.isNaN(Number(shift)) === true) { - throw new Error('Invalid Shift Provided') - } else { - shift = Number(shift); - } + // If required for very strict shift checking then remove '=0' + if (Number.isNaN(Number(shift)) === true) { + throw new Error('Invalid Shift Provided'); + } else { + shift = Number(shift); + } - if(typeof(toEncipher) === 'string' || (typeof(toEncipher) === 'number' && Number.isNaN(toEncipher) === false)) { - toEncipher = String(toEncipher); - } else { - throw new Error('Invalid string provided'); - } + if (typeof (toEncipher) === 'string' || (typeof (toEncipher) === 'number' && Number.isNaN(toEncipher) === false)) { + toEncipher = String(toEncipher); + } else { + throw new Error('Invalid string provided'); + } - // These are the valid entries aacepted, you can change it according to requirements - const validEntries = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; + // These are the valid entries aacepted, you can change it according to requirements + const validEntries = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; - shift %= validEntries.length; + shift %= validEntries.length; - let output = ''; - for (let char of toEncipher) { - if (char === ' ') { - output += ' '; - continue; - //------- If you donot want to accept invalid entries then uncomment below block + let output = ''; + for (const char of toEncipher) { + if (char === ' ') { + output += ' '; + continue; + // ------- If you donot want to accept invalid entries then uncomment below block /* ======================================================================================================== } else if (validEntries.indexOf(char) === -1) {return Error ('invalid character' + char)} ======================================================================================================== and comment out the below block */ - //======================================================================================================= - } else if (validEntries.indexOf(char) === -1) { - output += char; - continue; - } - //======================================================================================================= - output += (validEntries.indexOf(char) + shift <= validEntries.length) ? validEntries[validEntries.indexOf(char) + shift] : validEntries[(validEntries.indexOf(char) + shift) % validEntries.length]; + //= ====================================================================================================== + } else if (validEntries.indexOf(char) === -1) { + output += char; + continue; } - return output; + //= ====================================================================================================== + output += (validEntries.indexOf(char) + shift <= validEntries.length) ? validEntries[validEntries.indexOf(char) + shift] : validEntries[(validEntries.indexOf(char) + shift) % validEntries.length]; + } + return output; } -module.exports = caesarCipher; \ No newline at end of file +module.exports = caesarCipher; diff --git a/src/_Classics_/caesar_cipher/index.js b/src/_Classics_/caesar_cipher/index.js deleted file mode 100644 index 8851bf03..00000000 --- a/src/_Classics_/caesar_cipher/index.js +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Most simplest encryption scheme. Read more: [http://practicalcryptography.com/ciphers/caesar-cipher/] - * @param {String} str - * @param {Number} num - */ - -function caesarCipher(str, num) { - if (!num) throw new Error('Missing argument: num'); - - const lowerCaseString = str.toLowerCase(); - const alphabets = 'abcdefghijklmnopqrstuvwxyz'.split(''); - const totalAlphabets = alphabets.length; - let result = ''; - - // handle large number, like 300 or -300 - num %= totalAlphabets; - - const alphabetsMap = new Map(); - - for (const index in alphabets) { - alphabetsMap[alphabets[index]] = index; - } - - for (let index in lowerCaseString) { - // get the current character - const currentCharacter = lowerCaseString[index]; - - // if character is space, add it to the result and continue to next - if (currentCharacter === ' ') { - result += currentCharacter; - continue; - } - - // determine the new index - /** - * const currentIndex = alphabets.indexOf(currentCharacter); - * - * With indexOf complexity will be O(n*26) - * With Map complexity will be O(n). - */ - const currentIndex = Number(alphabetsMap[currentCharacter]); - let newIndex = currentIndex + num; - - // if the index passes 25, restart from 0 - if (newIndex > totalAlphabets - 1) { - newIndex -= totalAlphabets; - } - - if (newIndex < 0) { - newIndex = totalAlphabets + newIndex; - } - - // check if the character in original string was upper case - if (str[index] === str[index].toUpperCase()) { - result += alphabets[newIndex].toUpperCase(); - } else { - result += alphabets[newIndex]; - } - } - return result; -} From 6b3d07a001ec3d1e8ff7e48fd3cbfb8b3c3df82c Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Sat, 12 Oct 2019 14:07:25 +0530 Subject: [PATCH 10/12] all the comparisions in caesarCipher.test repaired --- .../caesar_cipher/caesarCipher.test.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/_Classics_/caesar_cipher/caesarCipher.test.js b/src/_Classics_/caesar_cipher/caesarCipher.test.js index e8d43042..ed559cdd 100644 --- a/src/_Classics_/caesar_cipher/caesarCipher.test.js +++ b/src/_Classics_/caesar_cipher/caesarCipher.test.js @@ -2,33 +2,25 @@ /* eslint-disable no-else-return */ const caesarCipher = require('./caeserCipher'); -const compareString = (str1, str2) => { - if (str1 === str2) { - return true; - } else { - return false; - } -}; - describe('Caesar Cipher tests', () => { it('Shift not passed', () => { const ocString = 'Hello World'; const enCiphered = caesarCipher(ocString); - expect(compareString(ocString, enCiphered)).toBe(true); + expect(ocString).toBe(enCiphered); }); it('Encipher equals decipher', () => { const ocString = 'Hello World'; const enCiphered = caesarCipher(ocString, 1); const deCiphered = caesarCipher(enCiphered, -1); - expect(compareString(ocString, deCiphered)).toBe(true); + expect(ocString).toBe(deCiphered); }); it('Shift lower than string length works', () => { const ocString = 'Hello World'; const enCiphered = caesarCipher(ocString, 1); const idealResult = 'Ifmmp Xpsme'; - expect(compareString(enCiphered, idealResult)).toBe(true); + expect(enCiphered).toBe(idealResult); }); it('Shift Higher than string length works', () => { @@ -42,15 +34,14 @@ describe('Caesar Cipher tests', () => { const ocString = 'Ifmmp Xpsme'; const enCiphered = caesarCipher(ocString, -1); const idealResult = 'Hello World'; - expect(compareString(enCiphered, idealResult)).toBe(true); + expect(enCiphered).toBe(idealResult); }); it('Shift is a numerical string', () => { const ocString = 'Hello World'; const enCiphered = caesarCipher(ocString, '1'); const idealResult = 'Ifmmp Xpsme'; - expect(compareString(enCiphered, idealResult)).toBe(true); - // toThrowError + expect(enCiphered).toBe(idealResult); }); it('Shift is not a numbered string', () => { From dc1453c139aa501c5cc3b80ae2b97536d527e9f9 Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Sat, 12 Oct 2019 14:09:12 +0530 Subject: [PATCH 11/12] caesarCipher.test comparision repair done. --- src/_Classics_/caesar_cipher/caesarCipher.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_Classics_/caesar_cipher/caesarCipher.test.js b/src/_Classics_/caesar_cipher/caesarCipher.test.js index ed559cdd..cfa68026 100644 --- a/src/_Classics_/caesar_cipher/caesarCipher.test.js +++ b/src/_Classics_/caesar_cipher/caesarCipher.test.js @@ -27,7 +27,7 @@ describe('Caesar Cipher tests', () => { const ocString = 'Hello World'; const enCiphered = caesarCipher(ocString, 63); const idealResult = caesarCipher(ocString, 1); - expect(compareString(enCiphered, idealResult)).toBe(true); + expect(enCiphered).toBe(idealResult); }); it('Negative shift Works', () => { From c6d32bd43861949aa65de199e74e3bcccd849686 Mon Sep 17 00:00:00 2001 From: OMKAR AGRAWAL Date: Mon, 21 Oct 2019 13:21:06 +0530 Subject: [PATCH 12/12] fixed issue with decimal shift values. --- src/_Classics_/caesar_cipher/caeserCipher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_Classics_/caesar_cipher/caeserCipher.js b/src/_Classics_/caesar_cipher/caeserCipher.js index d2a9a9d8..3988dafe 100644 --- a/src/_Classics_/caesar_cipher/caeserCipher.js +++ b/src/_Classics_/caesar_cipher/caeserCipher.js @@ -6,7 +6,7 @@ function caesarCipher(toEncipher, shift = 0) { if (Number.isNaN(Number(shift)) === true) { throw new Error('Invalid Shift Provided'); } else { - shift = Number(shift); + shift = parseInt(Number(shift), 10); } if (typeof (toEncipher) === 'string' || (typeof (toEncipher) === 'number' && Number.isNaN(toEncipher) === false)) {