Skip to content

Commit

Permalink
offset of 4 implicit to the exported Decode
Browse files Browse the repository at this point in the history
  • Loading branch information
auyer committed Apr 26, 2019
1 parent ce58e76 commit 67b3196
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/stego.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
26 changes: 20 additions & 6 deletions steganography.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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

}

Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions steganography_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 67b3196

Please sign in to comment.