A lot of refactoring, and etc #232

Open
Rudxain wants to merge 62 commits from Rudxain/patch-1 into master
Showing only changes of commit e9f84b69b1 - Show all commits

View file

@ -1,8 +1,8 @@
//converts input base64 into its URL-safe variant
let toURLsafe = str => str.replace(/./gs, c => ({'/': '_', '+': '-'}[c] || c))
//let toURLsafe = str => str.replace(/./gs, c => ({'/': '_', '+': '-'}[c] || c))
//https://nodejs.org/docs/latest/api/buffer.html#buffers-and-character-encodings
module.exports = class XOR {
xor(str, key) { return String.fromCodePoint(...str.split('').map((c, i) => c.charCodeAt(0) ^ key.toString().charCodeAt(i % key.toString().length))) }
encrypt(str, key = 37526) { return toURLsafe(Buffer.from(this.xor(str, key)).toString('base64')) }
decrypt(str, key = 37526) { return this.xor(Buffer.from(toURLsafe(str), 'base64').toString(), key) }
}
encrypt(str, key = 37526) { return Buffer.from(this.xor(str, key)).toString('base64url') }
decrypt(str, key = 37526) { return this.xor(Buffer.from(str, 'base64').toString(), key) }
}