From 988525177cd221d23a1cadc8550633534fceb323 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Tue, 20 Feb 2018 23:05:02 -0700 Subject: [PATCH] Replace non-characters with '-' instead of '' to mark punctuation --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a309f2b..a91d5a3 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,8 @@ const CHARS = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '$' + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + '&', '$', ]; const generatePad = (string) => { @@ -14,7 +15,7 @@ const generatePad = (string) => { } export const encrypt = (string) => { - const strippedString = string.replace(/[\s]+/g, '$').replace(/[^a-zA-Z0-9\$]/g, ''); + const strippedString = string.replace(/[\s]+/g, '&').replace(/[^a-zA-Z0-9\&]/g, '$'); const pad = generatePad(strippedString); return { oneTimePad: pad, @@ -33,7 +34,7 @@ export const decrypt = (string, pad) => { let charIndex = (letterValue - padValue); while (charIndex < 0) {charIndex += CHARS.length} return CHARS[charIndex % CHARS.length]; - }).join('').replace(/\$/g, ' '); + }).join('').replace(/\&/g, ' ').replace(/\$/g, '-'); } document.getElementById('encryptInput').onclick = () => {