Replace non-characters with '-' instead of '' to mark punctuation
This commit is contained in:
parent
e38a705cf6
commit
988525177c
7
index.js
7
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 = () => {
|
||||
|
|
Loading…
Reference in New Issue