Skip to main content
معرف التجربة: 003

Steganography Tool

CONCEPT

LSB (Least Significant Bit) image steganography in Go. Embeds a length-prefixed payload into the red channel of PNG pixels.

الهدف

Implement a covert channel by modifying the least significant bits of image pixel data, then verify extraction round-trips cleanly.

القيود

Payload size limited to (width × height) / 8 bytes. Not robust against JPEG re-encoding or image resizing.

Go Cryptography Image Processing
src/main.go
1package main
2
3import (
4 "encoding/binary"
5 "fmt"
6 "image"
7 "image/color"
8 "image/png"
9 "os"
10)
11
12func embed(img *image.NRGBA, payload []byte) error {
13 header := make([]byte, 4)
14 binary.BigEndian.PutUint32(header, uint32(len(payload)))
15 bits := append(header, payload...)
16
17 idx := 0
18 for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
19 for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
20 if idx >= len(bits)*8 {
21 return nil
22 }
23 c := img.NRGBAAt(x, y)
24 bytePos, bitPos := idx/8, uint(7-idx%8)
25 bit := (bits[bytePos] >> bitPos) & 1
26 c.R = (c.R & 0xFE) | bit
27 img.SetNRGBA(x, y, color.NRGBA{R: c.R, G: c.G, B: c.B, A: c.A})
28 idx++
29 }
30 }
31 return fmt.Errorf("image too small for payload")
32}
33
34func main() {
35 f, _ := os.Open("cover.png")
36 defer f.Close()
37 src, _ := png.Decode(f)
38
39 dst := image.NewNRGBA(src.Bounds())
40 for y := dst.Bounds().Min.Y; y < dst.Bounds().Max.Y; y++ {
41 for x := dst.Bounds().Min.X; x < dst.Bounds().Max.X; x++ {
42 dst.Set(x, y, src.At(x, y))
43 }
44 }
45
46 _ = embed(dst, []byte("CLASSIFIED_PAYLOAD"))
47
48 out, _ := os.Create("stego.png")
49 defer out.Close()
50 png.Encode(out, dst)
51 fmt.Println("Done — payload embedded into stego.png")
52}
وضع القراءة فقطUTF-8