Skip to content

Commit

Permalink
* Move from Buffer to Text Decoder/Encoder
Browse files Browse the repository at this point in the history
* Fixed #18 issue
* Updated README.md
  • Loading branch information
Andrii Medvediev committed Mar 19, 2023
1 parent ed3831f commit 975bff8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ The program works in two modes, encrypt and decrypt messages.
To encrypt a message use one of the following commands:

```sh
$ stegjs img.png -e 'Meeting tonight at midnight under the light.' 5x5
$ stegjs https://google.com/img.png -e 'Xod(}bgwh2^j7>B8X' 1x1 ./secrets/go.png
$ stegjs nyan.png -e '🐱' 2x1
$ npx stegjs img.png -e "Meeting tonight at midnight under the light." 5x5
$ npx stegjs https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png -e "my_secret_pass" 1x1 ./secrets/go.png
$ npx stegjs nyan.png -e "🐱" 2x1
```

After that in the console, you will see the full path to the output image, message and pattern.
Expand All @@ -71,7 +71,7 @@ To receive an encrypted message, specify the path to the image with the secret m


```sh
$ stegjs out.png -d
$ npx stegjs out.png -d
```

After that in the console, you will see the information contained in the encrypted image.
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "stegjs",
"version": "2.0.4",
"version": "2.0.6",
"description": "Encrypt message to PNG image.",
"main": "lib/index.js",
"types": "lib",
"main": "lib/src/index.js",
"types": "lib/src",
"scripts": {
"lint": "eslint . --ext .ts",
"build": "rimraf ./lib && tsc -p . --sourcemap",
Expand All @@ -19,7 +19,7 @@
"test:dev": "jest --watchAll --coverage --detectOpenHandles"
},
"bin": {
"stegjs": "lib/index.js"
"stegjs": "lib/src/index.js"
},
"husky": {
"hooks": {
Expand Down
10 changes: 6 additions & 4 deletions src/converters.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { TextDecoder, TextEncoder } from 'util';

/**
* The function converts string into an array of bits.
* @param str
* @returns {Array}
*/
export const stringToBits = (str: string): boolean[] => {
// Make a new buffer, based on our incoming message.
const buffer = Buffer.from(str);
const buffer = new TextEncoder().encode(str);

// Let's make an array of bits, based on each
// Let's make an array of bits, based on each byte in the buffer.
const bitarray = [];

for (let i = 0; i < buffer.length; i++) {
Expand All @@ -32,7 +34,7 @@ export const stringToBits = (str: string): boolean[] => {
* @returns {string|String}
*/
export const bitsToString = (bits: number[]): string => {
const buf = Buffer.alloc(bits.length / 8);
const buf = new Uint8Array(bits.length / 8);
let byteID = -1;

let myBytes = [];
Expand All @@ -59,7 +61,7 @@ export const bitsToString = (bits: number[]): string => {
myBytes = [];
}
}
return buf.toString();
return new TextDecoder().decode(buf);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Main Functionality', () => {
`ts-node ${join(__dirname, 'index.ts')} --version`,
);
expect(stderr).toEqual('');
expect(stdout).toEqual('2.0.4\n');
expect(stdout).toEqual('2.0.6\n');
});
it('prints StegJS help information', async () => {
const { stdout, stderr } = await exec(
Expand Down
18 changes: 10 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Have the option of writing a message into the image by pattern –
distance between the bits of the message.
Also the program can get the message
Also, the program can get the message
from already encoded PNG image.
A program developed by Andrey Medvedev in 2016.
Expand Down Expand Up @@ -67,12 +67,14 @@ program.on('--help', () => {
});

/** The arguments passed by the program. */
program.action((image, message, step, output) => {
imageValue = image;
messageValue = message;
stepValue = step;
outputValue = output;
});
program.action(
(image: string, message: string, step: string, output: string) => {
imageValue = image;
messageValue = message;
stepValue = step;
outputValue = output;
},
);

/** Parse arguments that come into the program. */
program.parse(process.argv);
Expand All @@ -88,7 +90,7 @@ if (typeof imageValue === 'undefined') {
/** If user does not specify output path, then throw output image to the current folder with name out.png */
outputValue = outputValue || join(process.cwd(), '/out.png');

/** Branching according of the program mode. */
/** Branching according to the program mode. */
if (program.opts()['encode']) {
encode(imageValue, messageValue, stepValue, outputValue);
}
Expand Down

0 comments on commit 975bff8

Please sign in to comment.