forked from KuroLabs/stegcloak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stegcloak.js
105 lines (82 loc) · 2.14 KB
/
stegcloak.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"use strict";
const R = require("ramda");
const {
encrypt,
decrypt
} = require("./components/encrypt");
const {
compress,
decompress,
zwcHuffMan
} = require("./components/compact");
const {
zwcOperations,
embed
} = require("./components/message");
const zwc = ["", "", "", "", "", "", ""]; // 200c,200d,2060,2061,2062,2063,2064 Where the magic happens !
const {
toConceal,
toConcealHmac,
concealToData,
noCrypt,
detach,
} = zwcOperations(zwc);
const {
shrink,
expand
} = zwcHuffMan(zwc);
const {
byteToBin,
compliment
} = require("./components/util");
class StegCloak {
constructor(_encrypt = true, _integrity = false) {
this.encrypt = _encrypt;
this.integrity = _integrity;
}
static get zwc() {
return zwc;
}
hide(message, password, cover = "This is a confidential text") {
if (cover.split(" ").length === 1) {
throw new Error("Minimum two words required");
}
const integrity = this.integrity;
const crypt = this.encrypt;
const secret = R.pipe(compress, compliment)(message); // Compress and compliment to prepare the secret
const payload = crypt ?
encrypt({
password: password,
data: secret,
integrity,
}) :
secret; // Encrypt if needed or proxy secret
const invisibleStream = R.pipe(
byteToBin,
integrity && crypt ? toConcealHmac : crypt ? toConceal : noCrypt,
shrink
)(payload); // Create an optimal invisible stream of secret
return embed(cover, invisibleStream); // Embed stream with cover text
}
reveal(secret, password) {
// Detach invisible characters and convert back to visible characters and also returns analysis of if encryption or integrity check was done
const {
data,
integrity,
encrypt
} = R.pipe(
detach,
expand,
concealToData
)(secret);
const decryptStream = encrypt ?
decrypt({
password,
data,
integrity,
}) :
data; // Decrypt if needed or proxy secret
return R.pipe(compliment, decompress)(decryptStream); // Receive the secret
}
}
module.exports = StegCloak;