Encryption / Dec Files "AES"

XOR & AES

encryption / decryption "XOR" Files

By XOR Target File Byte with AES Key File , It is Not Recoomend

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable:4996)

#define AES_KEY_SIZE 32
#define BUFFER_SIZE 4096

void xor_encrypt_decrypt(const unsigned char* key, const char* input_file, const char* output_file) {
    FILE* in = fopen(input_file, "rb");
    FILE* out = fopen(output_file, "wb");

    if (!in || !out) {
        perror("Failed to open file");
        exit(EXIT_FAILURE);
    }

    unsigned char buffer[BUFFER_SIZE];
    size_t bytes_read;

    while ((bytes_read = fread(buffer, 1, BUFFER_SIZE, in)) > 0) {
        for (size_t i = 0; i < bytes_read; i++) {
            buffer[i] ^= key[i % AES_KEY_SIZE]; // XOR with the key
        }
        fwrite(buffer, 1, bytes_read, out);
    }

    fclose(in);
    fclose(out);
    printf("Operation completed. Output saved to %s\n", output_file);
}

void load_aes_key(const char* filename, unsigned char* key) {
    FILE* file = fopen(filename, "rb");
    if (!file) {
        perror("Failed to open key file");
        exit(EXIT_FAILURE);
    }

    fread(key, 1, AES_KEY_SIZE, file);
    fclose(file);
}

int main() {
    char mode;
    char input_file[256], output_file[256];
    const char* key_file = "aes_key.bin";
    unsigned char key[AES_KEY_SIZE];

    load_aes_key(key_file, key);

    printf("Enter mode (e for encrypt, d for decrypt): ");
    scanf(" %c", &mode);
    printf("Enter input file name: ");
    scanf(" %255s", input_file);
    printf("Enter output file name: ");
    scanf(" %255s", output_file);

    if (mode == 'e') {
        xor_encrypt_decrypt(key, input_file, output_file);
    }
    else if (mode == 'd') {
        xor_encrypt_decrypt(key, input_file, output_file);
    }
    else {
        printf("Invalid mode. Use 'e' for encryption or 'd' for decryption.\n");
        return EXIT_FAILURE;
    }

    return 0;
}

2 - encryption / decryption Files With AES Key

This Code :

  • Gen AES Key Auto And Save It

  • Enc / Dec Large File

  • Add .crpt in File end

Alert !!!!!

This Code To Explane C prog language , And How to use it to encreption files with C

it's not to use a real word ransomware code .

Last updated