Hi, I need to write a simple encryption function so I found this online to get familiarized w/ it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void encrypt_data(FILE* input_file, FILE* output_file, char* key)
{
int key_count = 0; //Used to restart key if strlen(key) < strlen(encrypt)
int encrypt_byte;
//Loop through each byte of file until EOF
while( (encrypt_byte = fgetc(input_file)) != EOF)
{
//XOR the data and write it to a file
fputc(encrypt_byte ^ key[key_count], output_file);
//Increment key_count and start over if necessary
key_count++;
if(key_count == strlen(key))
key_count = 0;
}
}
Can someone explain to me why we reset key_count to zero.