stego

command module
v0.0.0-...-48f9e01 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

README

Stego CLI

Github Action Build Go Report Card

Stego is a command-line interface for encoding and decoding secret data in images, using the Least Significant Bit (LSB) steganography technique. Currently, Stego only supports PNG images, but is able to hide any type of data and files.

Stego achieves this by first prepending the size of the secret data to the data itself. It then writes each bit of the data to the least significant bit of each pixel's RGB values in the image. When Stego decodes an image, it collects each least significant bit of the image, then recompose the bits back into data. The first 8 LSB will tell Stego the total size of the hidden data.

Stego is also available as a Go package.

Getting Started

$ go get -u github.com/gzcharleszhang/stego

Usage

Encoding data in an image
$ stego encode ./stego/example.png --data "Stego is a steganography CLI tool."

By default, Stego will add a -out suffix to the output image. For example, the above encoded image can be found at ./stego/example-out.png

To specify an output path, use the --out or -o flag

$ stego encode ./stego/example.png -d "Stego is a steganography CLI tool." -o ./out/example.png

Use the --bits or -b flag to specify the number of bits in a byte used for encoding.

For example, this will tell Stego to use up to 2 bits per byte. If Stego already used all of the least significant bits in an image but there is still more data to encode, then Stego will encode using the second least significant bit.

$ stego encode ./stego/example.png -d "Stego is a steganography CLI tool." -b 2
Decoding data from an image
$ stego decode ./example.png
Stego is a steganography CLI tool.
Checking the maximum encoding size of an image

Before encoding data in an image, you may want to know how much hidden data an image can hold.

Stego has a size command that calculates the maximum encoding size of an image in bytes.

$ stego size ./example.png
1179644

Use the --bits or -b flag to specify the number of bits in a byte used for encoding.

$ stego size ./example.png -b 2
2359292

Pretty print using the --pretty or -p flag.

$ stego size --pretty ./example.png
1.12 MB

Using Stego as a package

Package-only installation
$ go get -u github.com/gzcharleszhang/stego/pkg/stegolsb
Encoding

Stego can encode data into an image from the Go image package

import (
    "fmt"
    "github.com/gzcharleszhang/stego/pkg/stegolsb"
    "image"
	"image/png"
	"os"
)

func main() {
    // read image from file
    file, _ := os.Open("/path/to/image")
    img, _, _ := image.Decode(file)
 
    // encode data using Stego
    outImg, err := stego_lsb.LSBEncode(img, "Hello, world!")
    if err != nil {
        fmt.Printf("Error encoding data: %v\n", err)
    }
}
Encoding with more than 1 bit

The package also supports encoding with multiple bits per byte. This allows the image to encode more data, however it will decrease the encoded image quality compared to the original image.

Stego will first use the least significant bit, then the second least significant bit, and so on.

Encoding an image using up to 2 bit per byte

outImg, err := stego_lsb.Encode(img, "Hello, world!", 2)
if err != nil {
    fmt.Printf("Error encoding data: %v\n", err)
}
Decoding

Stego attempts to decode an image and prints the hidden data.

data, err := stego_lsb.Decode(img)
if err != nil {
    fmt.Printf("Error decoding image: %v\n", err)
}
Maximum encoding size

Stego can calculate the maximum number of bytes available for encoding in an image.

maxSize, err := stego_lsb.MaxLSBEncodeSize(img)
if err != nil {
    fmt.Printf("Error getting max encode size: %v", err)
}

Use stego_lsb.MaxEncodeSize to get the max size if using more than 1 bit per byte for encoding.

The maximum number of bytes available in the image when using up to 2 bits per byte for encoding.

maxSize, err := stego_lsb.MaxEncodeSize(img, 2)
if err != nil {
    fmt.Printf("Error getting max encode size: %v", err)
}

Documentation

Overview

Copyright © 2020 Charles Zhang

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL