-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdecrypt.js
35 lines (33 loc) · 1007 Bytes
/
decrypt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* ==========================================================================
*
* Use:
* "WzM3NDQyLDUyNDg4LDU1ODc0LDU2MDcyLDU3NDEwLDE3MTYwLDQ1MTIyLDU3NjA4LDU4OTQ2LDU2MDcyLDUxNzc4XQ==".decrypt("key")
* => "Hello World!"
*
* ========================================================================== */
String.prototype.encode = function() {
let array = [];
for (let i of this) {
array.push(i.charCodeAt(0))
}
return array
}
String.prototype.decrypt = function(key) {
const keyEncoded = key.encode()
if (typeof atob === 'undefined') {
global.atob = b64Encoded => new Buffer(b64Encoded, 'base64').toString();
}
let array = JSON.parse(
atob(this.toString())
)
let decrypted = array.map(x => {
keyEncoded.reverse()
x = parseInt(x)
for (let i of keyEncoded) {
x = x - 1 >> i % 8
}
return x;
})
return String.fromCharCode(...decrypted)
}
module.exports = (text, key) => text.decrypt(key)