I'm working on a coding challenge where I have to read n bytes from an encoded file and perform some operations with them. I am trying to get the integer value of the bytes to use as a seed for srand().
I'm not sure I'm doing this properly. I am passing in 4 and file pointer to read_n_bytes() in which I am reading 4 bytes from the file and writing them to a location in memory set aside with malloc(). Then returning the malloc() address as a char pointer as seed and attempting to access the bytes with &seed.
The rest of my operation isn't working here.
Am I going about this the right way?
char* seed;
int main() {
FILE * fp;
fp = fopen("flag.enc", "rb");
// extract seed from flag
seed = read_n_bytes(4, fp);
srand(&seed);
}
char* read_n_bytes(int b, FILE * fp) {
char * buffer;
buffer = malloc(b);
fread(buffer, 1, b, fp);
return buffer;
}