Add export to encrypt and decrypt functions

This commit is contained in:
Robbie Antenesse 2018-02-20 22:55:29 -07:00
parent e825dfc1d5
commit 1501f6729f
1 changed files with 3 additions and 4 deletions

View File

@ -4,7 +4,7 @@ const CHARS = [
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
]; ];
function generatePad(string) { const generatePad = (string) => {
const pad = []; const pad = [];
for (let i = 0; i < string.length; i++) { for (let i = 0; i < string.length; i++) {
const letter = Math.floor(Math.random() * CHARS.length); const letter = Math.floor(Math.random() * CHARS.length);
@ -13,9 +13,8 @@ function generatePad(string) {
return pad; return pad;
} }
function encrypt(string) { export const encrypt = (string) => {
const strippedString = string.replace(/[^a-zA-Z0-9]/g, ''); const strippedString = string.replace(/[^a-zA-Z0-9]/g, '');
console.log('strippedString', strippedString);
const pad = generatePad(strippedString); const pad = generatePad(strippedString);
return { return {
oneTimePad: pad, oneTimePad: pad,
@ -27,7 +26,7 @@ function encrypt(string) {
}; };
} }
function decrypt(string, pad) { export const decrypt = (string, pad) => {
return string.split('').map((letter, index) => { return string.split('').map((letter, index) => {
const letterValue = CHARS.indexOf(letter); const letterValue = CHARS.indexOf(letter);
const padValue = CHARS.indexOf(pad[index]); const padValue = CHARS.indexOf(pad[index]);