Files
BUT2FI_R4.B.10_2026/tp/tp1/src/ex2/lfsr.c
2026-03-02 18:34:04 +01:00

37 lines
685 B
C

#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
unsigned char next(
unsigned char lfsr, // le registre
unsigned char retroaction_f // les bits selectionnés par la
) // fonction de retroaction
{
// TODO
}
int main(int argc, char *argv[])
{
int fd_in,fd_out;
unsigned char w,buf,f;
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);
f = ; // TODO
while(1){
ssize_t nb = read(fd_in,&buf,1);
if (nb <=0)
break;
buf ^= w;
write(fd_out,&buf,1);
w=next(w,f);
}
return 0;
}