diff --git a/examples/stego.go b/examples/stego.go index d4b9ca4..d669bcf 100644 --- a/examples/stego.go +++ b/examples/stego.go @@ -99,7 +99,7 @@ func main() { sizeOfMessage := steganography.GetMessageSizeFromImage(img) // Uses the library to check the message size - msg := steganography.Decode(4, sizeOfMessage, img) // Read the message from the picture file + msg := steganography.Decode(sizeOfMessage, img) // Read the message from the picture file // if the user specifies a location to write the message to... if messageOutputFile != "" { diff --git a/steganography.go b/steganography.go index f047503..0f670fc 100644 --- a/steganography.go +++ b/steganography.go @@ -106,7 +106,7 @@ func Encode(writeBuffer *bytes.Buffer, pictureInputFile image.Image, message []b } -// DecodeRGBA gets messages from pictures using LSB steganography, decode the message from the picture and return it as a sequence of bytes +// decodeRGBA gets messages from pictures using LSB steganography, decode the message from the picture and return it as a sequence of bytes /* Input: startOffset uint32 : number of bytes used to declare size of message @@ -115,7 +115,7 @@ func Encode(writeBuffer *bytes.Buffer, pictureInputFile image.Image, message []b Output: message []byte decoded from image */ -func DecodeRGBA(startOffset uint32, msgLen uint32, rgbImage *image.RGBA) (message []byte) { +func decodeRGBA(startOffset uint32, msgLen uint32, rgbImage *image.RGBA) (message []byte) { var byteIndex uint32 var bitIndex uint32 @@ -187,7 +187,7 @@ func DecodeRGBA(startOffset uint32, msgLen uint32, rgbImage *image.RGBA) (messag return } -// Decode gets messages from pictures using LSB steganography, decode the message from the picture and return it as a sequence of bytes +// decode gets messages from pictures using LSB steganography, decode the message from the picture and return it as a sequence of bytes // It wraps EncodeRGBA making the conversion from image.Image to image.RGBA /* Input: @@ -197,10 +197,24 @@ func DecodeRGBA(startOffset uint32, msgLen uint32, rgbImage *image.RGBA) (messag Output: message []byte decoded from image */ -func Decode(startOffset uint32, msgLen uint32, pictureInputFile image.Image) (message []byte) { +func decode(startOffset uint32, msgLen uint32, pictureInputFile image.Image) (message []byte) { rgbImage := imageToRGBA(pictureInputFile) - return DecodeRGBA(startOffset, msgLen, rgbImage) + return decodeRGBA(startOffset, msgLen, rgbImage) + +} + +// Decode gets messages from pictures using LSB steganography, decode the message from the picture and return it as a sequence of bytes +// It wraps EncodeRGBA making the conversion from image.Image to image.RGBA +/* + Input: + msgLen uint32 : size of the message to be decoded + pictureInputFile image.Image : image data used in decoding + Output: + message []byte decoded from image +*/ +func Decode(msgLen uint32, pictureInputFile image.Image) (message []byte) { + return decode(4, msgLen, pictureInputFile) // the offset of 4 skips the "header" where message lenght is defined } @@ -220,7 +234,7 @@ func MaxEncodeSize(img image.Image) uint32 { // GetMessageSizeFromImage gets the size of the message from the first four bytes encoded in the image func GetMessageSizeFromImage(pictureInputFile image.Image) (size uint32) { - sizeAsByteArray := Decode(0, 4, pictureInputFile) + sizeAsByteArray := decode(0, 4, pictureInputFile) size = combineToInt(sizeAsByteArray[0], sizeAsByteArray[1], sizeAsByteArray[2], sizeAsByteArray[3]) return } diff --git a/steganography_test.go b/steganography_test.go index c54b94d..4d5471d 100644 --- a/steganography_test.go +++ b/steganography_test.go @@ -65,7 +65,7 @@ func TestDecodeFromFile(t *testing.T) { sizeOfMessage := GetMessageSizeFromImage(img) - msg := Decode(4, sizeOfMessage, img) // Read the message from the picture file + msg := Decode(sizeOfMessage, img) // Read the message from the picture file if !bytes.Equal(msg, bitmessage) { log.Println(string(msg)) @@ -106,7 +106,7 @@ func TestEncodeDecodeGeneratedSmallImage(t *testing.T) { sizeOfMessage := GetMessageSizeFromImage(decodeImg) - msg := Decode(4, sizeOfMessage, decodeImg) // Read the message from the picture file + msg := Decode(sizeOfMessage, decodeImg) // Read the message from the picture file // otherwise, print the message to STDOUT