-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoding.js
52 lines (34 loc) · 1.41 KB
/
encoding.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// function obfuscateStringWithKey(textToObfuscate, encodingKey) {
// let encodingKeyBytes = Buffer.from(encodingKey);
// let encodingKeyLen = encodingKeyBytes.length;
// let textToObfuscateBytes = Buffer.from(textToObfuscate);
// let textToObfuscateLen = textToObfuscate.length;
// if (encodingKeyLen == 0 || textToObfuscateLen == 0) {
// return ""
// }
// let obfuscatedTextBytes = [];
// for (let i = 0; i < textToObfuscateLen; i++) {
// obfuscatedTextBytes[i] = textToObfuscateBytes[i] ^ encodingKeyBytes[i%encodingKeyLen]
// }
// let obfuscatedText = Buffer.from(obfuscatedTextBytes).toString('base64');
// return obfuscatedText
// }
const deobfuscate = function(textToDeobfuscate, encodingKey) {
// decode from base64
// perform bitwise XOR on the bytes using the encodingKey
// return the value
let decodedText = Buffer.from(textToDeobfuscate, 'base64').toString()
let encodingKeyBytes = Buffer.from(encodingKey);
let encodingKeyLen = encodingKeyBytes.length;
let textToDeobfuscateBytes = Buffer.from(decodedText);
let textToDeobfuscateLen = decodedText.length;
if (encodingKeyLen == 0 || textToDeobfuscateLen == 0) {
return ""
}
let deobfuscatedTextBytes = [];
for (let i = 0; i < textToDeobfuscateLen; i++) {
deobfuscatedTextBytes[i] = textToDeobfuscateBytes[i] ^ encodingKeyBytes[i%encodingKeyLen]
}
return Buffer.from(deobfuscatedTextBytes).toString();
}
module.exports = deobfuscate;