diff --git a/cli.js b/cli.js index 9a129ae..38d0bbc 100644 --- a/cli.js +++ b/cli.js @@ -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) { @@ -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 ', 'Extract cover text from file') @@ -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"]) { @@ -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) diff --git a/components/message.js b/components/message.js index c65511a..cac6355 100644 --- a/components/message.js +++ b/components/message.js @@ -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 { @@ -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(" "); };