Skip to content

Instantly share code, notes, and snippets.

@ckeyer
Created December 7, 2016 13:05
Show Gist options
  • Save ckeyer/7da0986801f4a58e4732a80e483ecfcd to your computer and use it in GitHub Desktop.
Save ckeyer/7da0986801f4a58e4732a80e483ecfcd to your computer and use it in GitHub Desktop.
IDF--CTF
package main
import (
"image"
"image/color"
"image/jpeg"
"log"
"os"
)
var (
fn = "idf_game_stego_059.jpg"
newf = "tmp.jpg"
)
func main() {
log.Println("hello")
f, err := os.Open(fn)
if err != nil {
log.Fatal(err)
}
defer f.Close()
j, err := jpeg.Decode(f)
if err != nil {
log.Fatal(err)
return
}
img := image.NewRGBA(image.Rect(0, 0, j.Bounds().Max.X, j.Bounds().Max.Y))
for x := 0; x < j.Bounds().Max.X; x++ {
for y := 0; y < j.Bounds().Max.Y; y++ {
c := j.At(x, y)
r, g, b, _ := c.RGBA()
nc := color.RGBA{225, 225, 225, 225}
if (g == 0 && b == 0) || !(r == b && b == g && b > 400) {
nc = color.RGBA{0, 0, 0, 225}
}
img.Set(x, y, nc)
}
}
writeJpg(img)
}
func writeJpg(i *image.RGBA) {
os.RemoveAll(newf)
f, err := os.OpenFile(newf, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
return
}
defer f.Close()
err = jpeg.Encode(f, i, &jpeg.Options{100})
if err != nil {
log.Fatal(err)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment