Contents

Pngme

Pngme

Encode and decode hidden messages in PNG files.

Repository

Introduction

This is an intermediate level personal project that I tackled in order to reinforce my knowledge of the Rust programming language. It was somewhat tough but it helped me a lot to get my feet more wet at writing a little more Rust and reading some official documentation.

This is my implementation or solution of this project but it is somewhat popular online, you can find it at Pngme. Taken from the text:

“I just finished reading The Book. What should I do next?”

This question comes up weekly in online Rust discussions. The answers to this question are always “Make something!”, sometimes followed by a list a cool projects. This is a great answer for some people, but others might be looking for a little more direction. This guide is intended to fill the gap between heavily directed beginner tutorials and working on your own projects. The primary goal here is to get you writing code. The secondary goal is to get you reading documentation.

The idea is to learn about and work around with the PNG specification, in order to manipulate the chunks of a given PNG image. This way, we can store text messages hidden inside a seemingly normal picture.

The project is divided in four main sections or chapters:

  1. Chunk Types
  2. Chunks
  3. PNG Files
  4. Command Line Arguments.

This approach helps the student to tackle problems one step at a time. Also, the author provides a basic skeleton to follow, along with his predefined tests.

I have to admit, this was tough. The first time I tried to implement this project, it really boggled my mind. But I came back some weeks later with a little more peace of mind and managed to slowly, but surely, complete it.

Installation

1
2
3
git clone https://github.com/UberChili/pngme.git
cd pngme
cargo build --release

Then you can run the executable via:

1
./target/release/pngme

Or you can install globally so you can run it from anywhere:

1
cargo install --path .

Usage

Run without any arguments to get a list of possible commands:

1
pngme 
  • Commands:
    • encode
    • decode
    • remove
    • print
    • help

Run a command without additional arguments to get a list of the needed options:

1
2
3
pngme <COMMAND>
# For example
pngme encode

Encoding a message in a PNG file:

1
pngme encode --filepath [filename.png] --chunk-type rUsT --message "Hello, this is a very secret message!" --out-file [out_name.png]

Decoding a message in a PNG file:

1
pngme decode --filepath [filename.png] --chunk-type rUsT

This would print:

1
Message: Hello, this is a very secret message!

As this was implemented while I was learning Rust, I think it has some ugly and likely unoptimized code, so I decided to try to implement it again, just as a learning reinforcement: Github