Last active
September 7, 2019 22:19
-
-
Save scottleedavis/cf07abde16e15d7abde990282869471a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"bytes" | |
"fmt" | |
"gopkg.in/auyer/steganography.v2" | |
"image" | |
"os" | |
) | |
func main() { | |
inFile, err := os.Open("./assets/pre_test.png") // opening file | |
if err != nil { | |
fmt.Println("unable to open file") | |
} | |
defer inFile.Close() | |
reader := bufio.NewReader(inFile) // buffer reader | |
img, _, err := image.Decode(reader) | |
if err != nil { | |
fmt.Println("ERROR: original image is corrupt " + err.Error()) | |
return | |
} | |
w := &bytes.Buffer{} | |
err = steganography.Encode(w, img, []byte("this is a watermark")) | |
if err != nil { | |
fmt.Println(err.Error()) | |
} | |
//Save file | |
outFile, err := os.Create("test.png") // Creates file to write the message into | |
if err != nil { | |
fmt.Println("Error creating file %s: %v", "test.png", err) | |
} | |
w.WriteTo(outFile) // this is more concise | |
outFile.Close() | |
//Read file | |
inFile2, err := os.Open("test.png") | |
if err != nil { | |
fmt.Println("unable to open file") | |
} | |
defer inFile2.Close() | |
reader = bufio.NewReader(inFile2) | |
img, _, err = image.Decode(reader) | |
if err != nil { | |
fmt.Println("unable to decode file") | |
} | |
sizeOfMessage := steganography.GetMessageSizeFromImage(img) | |
msg := steganography.Decode(sizeOfMessage, img) | |
fmt.Println("**** " + string(msg)) | |
} |
Awesome, thank you for the feedback. I made the changes you mention above, however the output is a blank message for me
$ go run test_infile.go
****
updated with new png, and it works. must be the original png corrupted?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Besides what I mentioned above, I would change a few things:
L 36 :
L 37 : close the outFile