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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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).