tp1
This commit is contained in:
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;
|
||||
}
|
Reference in New Issue
Block a user