Visual cryptography
In order to make sense of some of the things we mentioned in class, it is useful to see them in action on image files; for we, as humans, are quite good at visually detecting patterns in an array of pixels. This "cloud" interface to Sage is somewhat similar to the regular "notebook" one; use SHIFT+ENTER (or the green "Run" button above) to evaluate a cell.
1) First attempt
Here is a picture of Bletchley Park, where modern computing was born as Alan Turing and thousands of cryptananalysists worked on the breaking of the German codes during WWII:


Internally, it's just a matrix of pixels, each of which is colored according to a RGB triple of integers between 0 and 255:
Recall that the goal of encryption would be to reversibly make it look like a random image of the same size just like this one:

As a single pixel is encoded on bits, a block of pixels is encoded on bits, which give us more than enough room to store a secure symmetric encryption key.
Let's derive from it an encryption mask by repeating this small block:

Et voilà! Here's the picture, encrypted by a 384-bit key:

Discuss the result. Would you say that this cipher provides perfect secrecy?
2) One-time pad
Go through the same process, this time with a genuine randomly generated one-time pad. What's the key-length this time? Verify that the cipher decrypts correctly, i.e. play both the roles of Alice and Bob to see that everything works as it should. Also make sure to take a look at what Eve actually sees on the insecure channel.
A défaut de trouver les bonnes méthodes pour trouver le résultat, voilà le raisonnement que j aurais :
On applique le RPGA sur l'image m
on formate bien le résultat pour obtenir une liste de triplets, ici comme l'exemple k d'avant, un bloc de 4x4 pixels composés chacun de 3 composantes (rgb) de valeurs comprises entre 0 et 255
On applique le XOR (pad + m) pour voir le résultat crypte, il suffit alors d'jaouter m pour retoruver pad ou bien d'ajouter pad pour retoruver m
Bob envoie l'image crypté et Alice pour retrouver l'image de base, applique le même filtre pour retrouver l'image de base
Le méchant Eve quant à lui obtient l'image pad + m



3) Two-time pad
Wow, this works well. In the excitation of the moment, I started encrypting all my images... but forgot to apply one of the most important usage rules of the one-time pad when I encrypted the following two images. Can you find out what they were?

4) Random number generator
After realizing my mistake, I decided to generate pads from a 128-bit key by using it as a seed for a linear congruence generator modulo the following 128-bit prime:
Since such a PRNG is characterized by two 128-bit integers and which were chosen at random, there should be more than enough entropy to protect my 128-bit key, right? Prove me wrong by finding out what the seed used to produce the first few outputs from the LCG was:
217692597915196650809181220736554072509,
101697276836279744146238049998237762682,
265181937610212296333751058245677871006,
84171444745593992579687306707926595136,
12455596861516498286468598807461112654,
...
Ici on calcule les deux premiers termes Y1 et Y2 qui valent X1-X0 et X2-X1, ensuite on sait que a = Y2*(Y1^-1), enfin b vaut (X1-a*X0)%p
Cependant je n'arrive pas à savoir où se toruve mon problème de syntaxe
5) Genuine stream cipher
Ok, now it's time to start doing things properly. We will use the still-standard-albeit-somewhat-deprecated RC4 pseudo-random number generator to generate a key-stream from a 128-bit key.
5) Genuine stream cipher
Ok, now it's time to start doing things properly. We will use the still-standard-albeit-somewhat-deprecated RC4 pseudo-random number generator to generate a key-stream from a 128-bit key. We first aquire 128 bits of "real" random data from the entropy pool of the system.