C6 adidas done

This commit is contained in:
Rens Pastoor
2025-06-16 11:22:40 +02:00
parent 3d69c8b93d
commit 04072d831e
4 changed files with 45 additions and 79 deletions

BIN
C/C5 and C6 Adidas/build/main Executable file

Binary file not shown.

View File

@@ -1,46 +1,31 @@
#include "channel.h" #include "channel.h"
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdint.h>
int channel_main(int argc, char* argv[]) int channel_main(int argc, char* argv[])
{ {
bool running = true;
FILE *input_file = fopen(argv[2], "rb"); FILE *input_file = fopen(argv[2], "rb");
if (input_file == NULL) { if (!input_file) {
fprintf(stderr, "Error opening input file: %s\n", argv[2]); fprintf(stderr, "Error opening input file: %s\n", argv[2]);
return 1; return 1;
} }
FILE *output_file = fopen(argv[3], "wb"); FILE *output_file = fopen(argv[3], "wb");
if (output_file == NULL) { if (!output_file) {
fprintf(stderr, "Error opening output file: %s\n", argv[3]); fprintf(stderr, "Error opening output file: %s\n", argv[3]);
fclose(input_file); fclose(input_file);
return 1; return 1;
} }
while (running){ uint8_t buffer[1024], processed[1024];
// Read data size_t bytes_read;
unsigned char buffer[1024]; while ((bytes_read = fread(buffer, 1, sizeof(buffer), input_file)) > 0) {
size_t bytes_read = fread(buffer, 1, sizeof(buffer), input_file); for (size_t i = 0; i < bytes_read; i++) {
processed[i] = channel_change_one_random_bit(buffer[i]);
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;
}
} }
fwrite(processed, 1, bytes_read, output_file);
// 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);
} }
fclose(input_file); fclose(input_file);
fclose(output_file); fclose(output_file);
printf("Channel completed successfully.\n");
return 0; return 0;
} }

View File

@@ -1,51 +1,45 @@
#include "decode.h" #include "decode.h"
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdint.h>
int decode_main(int argc, char* argv[]) int decode_main(int argc, char* argv[])
{ {
bool decoding = true;
FILE *input_file = fopen(argv[2], "rb"); FILE *input_file = fopen(argv[2], "rb");
if (input_file == NULL) { if (!input_file) {
fprintf(stderr, "Error opening input file: %s\n", argv[2]); fprintf(stderr, "Error opening input file: %s\n", argv[2]);
return 1; return 1;
} }
FILE *output_file = fopen(argv[3], "wb"); FILE *output_file = fopen(argv[3], "wb");
if (output_file == NULL) { if (!output_file) {
fprintf(stderr, "Error opening output file: %s\n", argv[3]); fprintf(stderr, "Error opening output file: %s\n", argv[3]);
fclose(input_file); fclose(input_file);
return 1; return 1;
} }
while (decoding)
{
// Read data
unsigned char data[1024];
unsigned char buffer_High[sizeof(data)/2];
unsigned char buffer_Low[sizeof(data)/2];
size_t bytes_read = fread(&data, 1, sizeof(data), input_file);
for (size_t i = 0; i < bytes_read; i++) {
buffer_High[i] = data[i + (sizeof(data)/2)];
buffer_Low[i] = data[i];
}
uint8_t buffer[2048], decoded[1024];
if (bytes_read == 0) { size_t bytes_read;
if (feof(input_file)) { // // b_r
decoding = false; // eof reached while ((bytes_read = fread(buffer, 1, sizeof(buffer), input_file)) > 0) {
} else { if (bytes_read % 2 != 0) { //odd check
fprintf(stderr, "Error reading from input file\n"); size_t extra = fread(buffer + bytes_read, 1, 1, input_file);
if (extra == 1) { // successfully read
bytes_read++;
} else { // error reading the extra byte
fclose(input_file); fclose(input_file);
fclose(output_file); fclose(output_file);
return 1; return 1;
} }
} }
// Decode data size_t decoded_size = bytes_read / 2;
unsigned char decoded_data[sizeof(data)]; for (size_t i = 0; i < decoded_size; i++) {
decoded_data[sizeof(data)] = decode_combine_nibbles(*buffer_High, *buffer_Low); decoded[i] = decode_combine_nibbles(buffer[i], buffer[i + decoded_size]);
}
// Write data fwrite(decoded, 1, decoded_size, output_file);
fwrite(decoded_data, 1, bytes_read, output_file);
} }
fclose(input_file);
fclose(output_file);
printf("Decoding completed successfully.\n");
return 0; return 0;
} }

View File

@@ -1,46 +1,33 @@
#include "encode.h" #include "encode.h"
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
int encode_main(int argc, char* argv[]) int encode_main(int argc, char* argv[])
{ {
bool encoding = true;
FILE *input_file = fopen(argv[2], "rb"); FILE *input_file = fopen(argv[2], "rb");
if (input_file == NULL) { if (!input_file) {
fprintf(stderr, "Error opening input file: %s\n", argv[2]); fprintf(stderr, "Error opening input file: %s\n", argv[2]);
return 1; return 1;
} }
FILE *output_file = fopen(argv[3], "wb"); FILE *output_file = fopen(argv[3], "wb");
if (output_file == NULL) { if (!output_file) {
fprintf(stderr, "Error opening output file: %s\n", argv[3]); fprintf(stderr, "Error opening output file: %s\n", argv[3]);
fclose(input_file); fclose(input_file);
return 1; return 1;
} }
while (encoding)
{
// Read data
unsigned char buffer[512];
size_t bytes_read = fread(buffer, 1, sizeof(buffer), input_file);
if (bytes_read == 0) { uint8_t buffer[1024], high[1024], low[1024];
if (feof(input_file)) { size_t bytes_read;
encoding = false; // eof reached while ((bytes_read = fread(buffer, 1, sizeof(buffer), input_file)) > 0) {
} else { for (size_t i = 0; i < bytes_read; i++) {
fprintf(stderr, "Error reading from input file\n"); encode_value(buffer[i], &high[i], &low[i]);
fclose(input_file);
fclose(output_file);
return 1;
}
} }
fwrite(high, 1, bytes_read, output_file);
// Encode data fwrite(low, 1, bytes_read, output_file);
unsigned char encoded_data_high[sizeof(buffer)];
unsigned char encoded_data_low[sizeof(buffer)];
encode_value(buffer, encoded_data_high, encoded_data_low);
// Write data
fwrite(encoded_data_high, 1, bytes_read, output_file);
fwrite(encoded_data_low, 1, bytes_read, output_file);
} }
fclose(input_file);
fclose(output_file);
printf("Encoding completed successfully.\n");
return 0; return 0;
} }