Skip to content

Commit

Permalink
fix: cipher with non-english characters
Browse files Browse the repository at this point in the history
  • Loading branch information
tiller1010 committed Apr 19, 2024
1 parent 68e6855 commit 03ab83b
Show file tree
Hide file tree
Showing 4 changed files with 87,169 additions and 10 deletions.
8 changes: 5 additions & 3 deletions app/cipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ function cipher(salt) {
function textToChars(text) {
return text.split('').map(function(c) { return c.charCodeAt(0); });
}

function byteHex(n) {
return ("0" + Number(n).toString(16)).substr(-2);
return '%' + Number(n).toString(16);
}

function applySaltToChar(code) {
return textToChars(salt).reduce(function(a,b) { return a ^ b; }, code);
return textToChars(salt).reduce(function(a, b) { return a ^ b; }, code);
}

return function(text) {
Expand All @@ -20,4 +22,4 @@ function cipher(salt) {

var myCipher = cipher(process.env.PROP_SALT);

module.exports = { myCipher };
module.exports = { myCipher };
8 changes: 4 additions & 4 deletions js/decipher.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const decipher = salt => {
const textToChars = text => text.split('').map(c => c.charCodeAt(0));
const applySaltToChar = code => textToChars(salt).reduce((a,b) => a ^ b, code);
return encoded => encoded.match(/.{1,2}/g)
.map(hex => parseInt(hex, 16))
const applySaltToChar = code => textToChars(salt).reduce((a, b) => a ^ b, code);
return encoded => encoded.match(/%\w+(?=%)?/g)
.map(hex => parseInt(hex.substr((hex.length -1) * -1), 16))
.map(applySaltToChar)
.map(charCode => String.fromCharCode(charCode))
.join('');
}

export default decipher;
export default decipher;
87,161 changes: 87,159 additions & 2 deletions public/js/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/main.js.map

Large diffs are not rendered by default.

0 comments on commit 03ab83b

Please sign in to comment.