Skip to content

Commit

Permalink
Merge pull request #15 from lcotonea/master
Browse files Browse the repository at this point in the history
[Enhancement] The payload position should not be predictable
  • Loading branch information
mohanpierce99 authored Jun 18, 2020
2 parents 6156d75 + a2e8897 commit 3ba169d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 34 deletions.
26 changes: 4 additions & 22 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const ora = require('ora')
const fs = require('fs')
const jsonfile = require('jsonfile');
const { zwcHuffMan } = require('./components/compact')
const { zwcOperations } = require("./components/message");
const { expand } = zwcHuffMan(StegCloak.zwc)
const { detach } = zwcOperations(StegCloak.zwc);


function cliHide(secret, password, cover, crypt, integrity, op) {
Expand Down Expand Up @@ -72,26 +74,6 @@ function cliReveal(payload, password, op) {
}, 300)
};

const detach = (str, zwc, invisible = true) => {
const payload = str.split(' ')[1]
const zwcBound = payload.split('')
const intersection = R.intersection(zwc, zwcBound)
if (intersection.length === 0) {
throw new Error('Invisible stream not detected ! Please copy paste the stegcloak text sent by the sender')
};
const limit = zwcBound.findIndex((x, i) => !(~zwc.indexOf(x)))

const zwcStream = payload.slice(0, limit)

const cleanedMessage = str.split(' ')[0] + (' ' + payload.slice(limit)) + str.split(' ').slice(2).join(' ')

if (invisible) {
return zwcStream
} else {
return cleanedMessage
}
}

program
.command('hide [secret] [cover]')
.option('-fc, --fcover <fcover> ', 'Extract cover text from file')
Expand Down Expand Up @@ -206,7 +188,7 @@ program

data = data || clipboardy.readSync()

const stream = expand(detach(data, StegCloak.zwc))
const stream = expand(detach(data))

if (stream[0] === StegCloak.zwc[2] || process.env["STEGCLOAK_PASSWORD"]) {
if (process.env["STEGCLOAK_PASSWORD"]) {
Expand All @@ -226,7 +208,7 @@ program

else {
inquirer.prompt([questions[0]]).then(answers => {
const stream = expand(detach(answers.payload, StegCloak.zwc))
const stream = expand(detach(answers.payload))

if (stream[0] === StegCloak.zwc[2]) {
cliReveal(answers.payload, null, args.output)
Expand Down
28 changes: 16 additions & 12 deletions components/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,19 @@ const zwcOperations = (zwc) => {
};

const detach = (str) => {
const payload = str.split(" ")[1];
const zwcBound = payload.split("");
const intersected = intersection(zwc, zwcBound);
if (intersected.length === 0) {
throw new Error(
"Invisible stream not detected ! Please copy paste the stegcloak text sent by the sender"
);
}
const limit = zwcBound.findIndex((x, i) => !~zwc.indexOf(x));
return payload.slice(0, limit);
const eachWords = str.split(" ");
eachWords.forEach((word)=>{
const zwcBound = word.split("");
const intersected = intersection(zwc, zwcBound);
if (intersected.length !== 0) {
const limit = zwcBound.findIndex((x, i) => !~zwc.indexOf(x));
return word.slice(0, limit);
}
});

throw new Error(
"Invisible stream not detected! Please copy and paste the StegCloak text sent by the sender."
);
};

return {
Expand All @@ -107,9 +110,10 @@ const zwcOperations = (zwc) => {

const embed = (cover, secret) => {
const arr = cover.split(" ");
return [arr[0]]
const targetIndex = Math.floor(Math.random() * Math.floor(arr.length/2));
return arr.slice(0, targetIndex+1)
.concat([secret + arr[1]])
.concat(arr.slice(2, arr.length))
.concat(arr.slice(targetIndex+1, arr.length))
.join(" ");
};

Expand Down

0 comments on commit 3ba169d

Please sign in to comment.