ajout crypto
This commit is contained in:
BIN
crypto/TP1/Ex1/file.crypt
Normal file
BIN
crypto/TP1/Ex1/file.crypt
Normal file
Binary file not shown.
16
crypto/TP1/Ex1/file.txt
Normal file
16
crypto/TP1/Ex1/file.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
Demain, dès l'aube, à l'heure où blanchit la campagne,
|
||||
Je partirai. Vois-tu, je sais que tu m'attends.
|
||||
J'irai par la forêt, j'irai par la montagne.
|
||||
Je ne puis demeurer loin de toi plus longtemps.
|
||||
|
||||
Je marcherai les yeux fixés sur mes pensées,
|
||||
Sans rien voir au dehors, sans entendre aucun bruit,
|
||||
Seul, inconnu, le dos courbé, les mains croisées,
|
||||
Triste, et le jour pour moi sera comme la nuit.
|
||||
|
||||
Je ne regarderai ni l'or du soir qui tombe,
|
||||
Ni les voiles au loin descendant vers Harfleur,
|
||||
Et quand j'arriverai, je mettrai sur ta tombe
|
||||
Un bouquet de houx vert et de bruyère en fleur.
|
||||
|
||||
— Victor Hugo, Les Contemplations, 3 septembre 1847
|
||||
BIN
crypto/TP1/Ex1/lfsr
Executable file
BIN
crypto/TP1/Ex1/lfsr
Executable file
Binary file not shown.
43
crypto/TP1/Ex1/lfsr.c
Normal file
43
crypto/TP1/Ex1/lfsr.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define MASK_BIT_7 0x80
|
||||
#define MASK_BIT_6 0x40
|
||||
#define MASK_BIT_5 0x20
|
||||
#define MASK_BIT_4 0x10
|
||||
#define MASK_BIT_3 0x08
|
||||
#define MASK_BIT_2 0x04
|
||||
#define MASK_BIT_1 0x02
|
||||
#define MASK_BIT_0 0x01
|
||||
|
||||
|
||||
unsigned char next(unsigned char lfsr)
|
||||
{
|
||||
unsigned char new_bit = __builtin_parity(lfsr & (MASK_BIT_7 | MASK_BIT_6 | MASK_BIT_5 | MASK_BIT_4 | MASK_BIT_3 | MASK_BIT_1));
|
||||
return (lfsr << 1) | new_bit;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fd_in,fd_out;
|
||||
unsigned char w,buf;;
|
||||
|
||||
|
||||
assert(argc >= 4);
|
||||
fd_in = open(argv[1],O_RDONLY);
|
||||
fd_out = open(argv[2],O_WRONLY|O_TRUNC|O_CREAT,0600);
|
||||
w = (unsigned char)strtol(argv[3],NULL,0);
|
||||
|
||||
while(1){
|
||||
ssize_t nb = read(fd_in,&buf,1);
|
||||
if (nb <=0)
|
||||
break;
|
||||
buf ^= w;
|
||||
write(fd_out,&buf,1);
|
||||
w=next(w);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user