From 4f521db029e210663d50ebd9e0ae0fe9791f0131 Mon Sep 17 00:00:00 2001 From: Sutthinart Khunvadhana Date: Mon, 12 Oct 2020 06:03:51 +0700 Subject: [PATCH 1/2] Add ROT13 cipher --- Ciphers/ROT13.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Ciphers/ROT13.js diff --git a/Ciphers/ROT13.js b/Ciphers/ROT13.js new file mode 100644 index 0000000000..76a78168c3 --- /dev/null +++ b/Ciphers/ROT13.js @@ -0,0 +1,21 @@ +/** + * Transcipher a ROT13 cipher + * @param {String} text - string to be encrypted + * @return {String} - decrypted string + */ +function transcipher (text) { + const originalCharacterList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' + const toBeMappedCharaterList = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm' + const index = x => originalCharacterList.indexOf(x) + const replace = x => index(x) > -1 ? toBeMappedCharaterList[index(x)] : x + return text.split('').map(replace).join('') +} + +(() => { + const messageToBeEncrypted = 'The quick brown fox jumps over the lazy dog' + console.log(`Original Text = "${messageToBeEncrypted}"`) + const rot13CipheredText = transcipher(messageToBeEncrypted) + console.log(`Ciphered Text = "${rot13CipheredText}"`) + const rot13DecipheredText = transcipher(rot13CipheredText) + console.log(`Deciphered Text = "${rot13DecipheredText}"`) +})() From c671a5154695cd6c6bb8e6011f881cae9e683a22 Mon Sep 17 00:00:00 2001 From: vinayak Date: Mon, 12 Oct 2020 13:04:08 +0530 Subject: [PATCH 2/2] Update ROT13.js --- Ciphers/ROT13.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ciphers/ROT13.js b/Ciphers/ROT13.js index 76a78168c3..24eeacf8e1 100644 --- a/Ciphers/ROT13.js +++ b/Ciphers/ROT13.js @@ -3,7 +3,7 @@ * @param {String} text - string to be encrypted * @return {String} - decrypted string */ -function transcipher (text) { +const transcipher = (text) => { const originalCharacterList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' const toBeMappedCharaterList = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm' const index = x => originalCharacterList.indexOf(x)