tp1
This commit is contained in:
BIN
tp1/ex1/decrypt
Executable file
BIN
tp1/ex1/decrypt
Executable file
Binary file not shown.
39
tp1/ex1/decrypt.c
Normal file
39
tp1/ex1/decrypt.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#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) {
|
||||
lfsr = lfsr << 1 | __builtin_parity(lfsr & 0xfa);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
16
tp1/ex1/fichierout.decrypt
Normal file
16
tp1/ex1/fichierout.decrypt
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
tp1/ex1/file.crypt
Normal file
BIN
tp1/ex1/file.crypt
Normal file
Binary file not shown.
Reference in New Issue
Block a user