image

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

gosteganography is a simple implementation of the LSB steganography algorithm in go, which uses the least significant bit (LSB) of each colour component (RGB) of each pixel of an image to hide a given message.

Example
input, err := os.Open(testImage)
if err != nil {
	fmt.Println(err)
	return
}
defer input.Close()
// open the input image
image, err := Read(input)
if err != nil {
	fmt.Println(err)
	return
}
// hide a message, it returns the number of bits written
expected := []byte("secret number: 1234")
nbits, err := image.Hide(expected)
if err != nil {
	fmt.Println(err)
	return
}
// get hided message using the number of bits
got := image.Unhide(nbits)
// store the output
output, err := os.Create("./output.png")
if err != nil {
	fmt.Println(err)
	return
}
defer output.Close()

if err := image.Write(output); err != nil {
	fmt.Println(err)
}
fmt.Println(string(got))
Output:

secret number: 1234

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrFormatNotSupported = fmt.Errorf("format not supported")
	ErrBytesLimitExceeded = fmt.Errorf("available bytes limit exceeded")
	ErrOpeningFile        = fmt.Errorf("error opening file")
	ErrDecodingImage      = fmt.Errorf("error decoding image")
	ErrWrittingFile       = fmt.Errorf("error writing file")
)

Functions

This section is empty.

Types

type Image

type Image struct {
	// contains filtered or unexported fields
}

Image struct abstracts the needed parameters to hide a message into it. It contains the original image.Image instance, the image type and the list of pixels.

func Read

func Read(input io.Reader) (*Image, error)

Read function instances a new Image struct from the io.Reader provided. It reads the original image and decodes it. It then initialises the Image pixels from the original image.Image.

func (*Image) BytesAvailable

func (i *Image) BytesAvailable() int

BytesAvailable returns the number of bytes the current image can safely hold. Actually, the maximun number of bytes that an Image can hold safely is calculated by multiplying the number of pixels by the number of colour components (three) and dividing by the number of bits in a byte.

func (*Image) Hide

func (i *Image) Hide(msg []byte) (int, error)

Hide function hides the provided message in the current Image. Before modify the Image pixels, it checks if the provided message exceeds the maximun number of bytes that the Image can hide safely. If the limit is not exceeded, it encodes the message in its binary representation and hides it in the Image pixels. If the limit is exceeded, it returns an ErrBytesLimitExceeded error.

func (*Image) Unhide

func (i *Image) Unhide(nbits int) []byte

Unhide function returns the hide message in the current Image with the length given as the `nbits` argument. If the number of bits in the hidden message is not correct, the result will be wrong (truncated or badly formatted).

func (*Image) Write

func (i *Image) Write(output io.Writer) error

Write function stores the current Image in io.Writer provided. It creates a new image.Image with the same dimensions of the original image and writes every Image pixel in the new one. Then write the new image.Image in the io.Writer provided.

Jump to

Keyboard shortcuts

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