C6 adidas done
This commit is contained in:
@@ -1,46 +1,31 @@
|
||||
#include "channel.h"
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int channel_main(int argc, char* argv[])
|
||||
{
|
||||
bool running = true;
|
||||
FILE *input_file = fopen(argv[2], "rb");
|
||||
if (input_file == NULL) {
|
||||
if (!input_file) {
|
||||
fprintf(stderr, "Error opening input file: %s\n", argv[2]);
|
||||
return 1;
|
||||
}
|
||||
FILE *output_file = fopen(argv[3], "wb");
|
||||
if (output_file == NULL) {
|
||||
if (!output_file) {
|
||||
fprintf(stderr, "Error opening output file: %s\n", argv[3]);
|
||||
fclose(input_file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (running){
|
||||
// Read data
|
||||
unsigned char buffer[1024];
|
||||
size_t bytes_read = fread(buffer, 1, sizeof(buffer), input_file);
|
||||
|
||||
if (bytes_read == 0) {
|
||||
if (feof(input_file)) {
|
||||
running = false; // eof reached
|
||||
} else {
|
||||
fprintf(stderr, "Error reading from input file\n");
|
||||
fclose(input_file);
|
||||
fclose(output_file);
|
||||
return 1;
|
||||
}
|
||||
uint8_t buffer[1024], processed[1024];
|
||||
size_t bytes_read;
|
||||
while ((bytes_read = fread(buffer, 1, sizeof(buffer), input_file)) > 0) {
|
||||
for (size_t i = 0; i < bytes_read; i++) {
|
||||
processed[i] = channel_change_one_random_bit(buffer[i]);
|
||||
}
|
||||
|
||||
// Channel data
|
||||
unsigned char processed_data[1024];
|
||||
size_t processed_size = process_channel(buffer, bytes_read, processed_data);
|
||||
|
||||
// Write data
|
||||
fwrite(processed_data, 1, processed_size, output_file);
|
||||
fwrite(processed, 1, bytes_read, output_file);
|
||||
}
|
||||
fclose(input_file);
|
||||
fclose(output_file);
|
||||
printf("Channel completed successfully.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user