Shape 2Shape 2Shape 2

SFML Image Encoder

This program for me was an early introduction to one of the uses of algorithms. Using Fibonacci’s sequence and a linear feedback shift register I was able to encode and decode images with a users desired 15 digit code.

Fibonacci's Sequence

Fibonacci's sequence is a series of numbers in which each number is the sum of the two preceding ones, starting from 0 and 1. The sequence typically begins as follows:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

The sequence can be defined by the recurrence relation:

F(n) = F(n−1) + F(n−2)

With the initial conditions:

F(0) = 0, F(1) = 1

Where F(n) represents the nth Fibonacci number.

Fibonacci's Sequence Example

Implementation

The code implements a Fibonacci LFSR by following a process similar to generating Fibonacci numbers, but instead of adding the numbers, it uses XOR operations on selected "tap" bits of the seed to generate a new bit. This new bit is then added to the sequence, and the seed is shifted, similar to how Fibonacci's sequence progresses by shifting and summing the last two numbers. Simulating a pseudo-random number sequence that uses the same iterative feedback principles as Fibonacci's sequence.

SFML

SFML is a C++ library that provides a simple interface for building multimedia applications. In my case it was used to manipulate a users provided image and display it after encoding and decoding. Using the previously described algorithm a pseudo-random RGB value is decided for each pixel in the image and reassigned to a new color based on the users given 15-digit input.

Fibonacci's Sequence Example

Encoding

Once the image is encoded, decoding it is just as simple. To unscramble the image, the user only needs to input the encoded image back into the program with the same 15-digit code used during encoding. The program then reverses the encoding process, using the same Fibonacci sequence algorithm and seed, to restore the image to its original state. Interestingly, the same image can be encoded multiple times with different keys, making it exponentially harder for anyone to decode the image through brute force.

Fibonacci's Sequence Example

Decoding

Visit the repository here!