Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- keyxorer by xerpi
- compile with:
- gcc -O3 keyxorer.c -o keyxorer
- usage:
- keyxorer <input file> <key file>
- the output will be <input file>.out
- *"big" input files and "small" keys*
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <malloc.h>
- void print_usage();
- int main(int argc, char *argv[])
- {
- int ret_val = EXIT_SUCCESS;
- if (argc < 3) {
- print_usage();
- ret_val = EXIT_FAILURE;
- goto exit_fail_1;
- }
- FILE *fd_in, *fd_key, *fd_out;
- if (!(fd_in = fopen(argv[1], "rb"))) {
- printf("Error opening input file\n");
- ret_val = EXIT_FAILURE;
- goto exit_fail_1;
- }
- if (!(fd_key = fopen(argv[2], "rb"))) {
- printf("Error opening key file\n");
- ret_val = EXIT_FAILURE;
- goto exit_fail_2;
- }
- fseek(fd_in, 0, SEEK_END);
- long int in_size = ftell(fd_in);
- fseek(fd_in, 0, SEEK_SET);
- fseek(fd_key, 0, SEEK_END);
- long int key_size = ftell(fd_key);
- fseek(fd_key, 0, SEEK_SET);
- unsigned char *key_buf = malloc(key_size);
- unsigned char *data_buf = malloc(key_size);
- if (key_size != fread(key_buf, 1, key_size, fd_key)) {
- printf("Cannot read key file\n");
- ret_val = EXIT_FAILURE;
- goto exit_fail_3;
- }
- char *out_name = malloc(strlen(argv[1]) + strlen(".out") + 1);
- sprintf(out_name, "%s.out", argv[1]);
- if (!(fd_out = fopen(out_name, "wb+"))) {
- printf("Cannot create output file\n");
- ret_val = EXIT_FAILURE;
- goto exit_fail_4;
- }
- #define BAR_LEN 50
- long int temp_read = 0;
- long int step_bytes = in_size/100;
- long int percent = 1;
- size_t bytes_read;
- while ((bytes_read = fread(data_buf, 1, key_size, fd_in))) {
- size_t i;
- for (i = 0; i < bytes_read; i++) {
- data_buf[i] ^= key_buf[i];
- }
- fwrite(data_buf, 1, bytes_read, fd_out);
- //Progress bar
- temp_read += bytes_read;
- if (temp_read >= step_bytes) {
- percent++;
- temp_read = 0;
- printf("%3li%% [", percent);
- int j;
- int bar_size = (BAR_LEN*percent)/100;
- for (j = 0; j < BAR_LEN; j++) {
- if (j < bar_size) printf("=");
- else if (j == bar_size) printf(">");
- else printf(" ");
- }
- printf("]\r");
- fflush(stdout);
- }
- }
- fflush(fd_out);
- fclose(fd_out);
- printf("\nFinished!\n");
- exit_fail_4:
- free(out_name);
- exit_fail_3:
- free(data_buf);
- free(key_buf);
- fclose(fd_key);
- exit_fail_2:
- fclose(fd_in);
- exit_fail_1:
- return ret_val;
- }
- void print_usage()
- {
- printf("keyxorer by xerpi\n"
- "usage: keyxorer <input file> <key file>\n"
- "the output will be <input file>.out\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement