<commit_before>/*
 * Code is taken from http://www.cypherspace.org/rsa/rc4.html and was adjusted
 * to the style guides and requirements within the CloudRAID project.
 */

#include "rc4.h"

#include <stdlib.h>

LIBEXPORT void swap_byte(unsigned char *a, unsigned char *b)
{
    unsigned char swapByte;

    swapByte = *a;
    *a = *b;
    *b = swapByte;
}

LIBEXPORT void prepare_key(const unsigned char *key_data_ptr, int key_data_len, rc4_key *key)
{
    unsigned char index1;
    unsigned char index2;
    unsigned char *state = NULL;
    short counter;
    unsigned char clean[3072];

    state = &key->state[0];
    for(counter = 0; counter < 256; counter++) {
        state[counter] = counter;
    }
    key->x = 0;
    key->y = 0;
    index1 = 0;
    index2 = 0;
    for(counter = 0; counter < 256; counter++) {
        index2 = (key_data_ptr[index1] + state[counter] + index2) % 256;
        swap_byte(&state[counter], &state[index2]);

        index1 = (index1 + 1) % key_data_len;
    }

    /*
     * It is recommendet to use the first 3072 bytes after initializing the key
     */
    for(counter = 0; counter < 3072; counter++) {
        clean[counter] = counter % 256;
    }
    rc4(clean, 3072, key);
}

LIBEXPORT void rc4(unsigned char *buffer_ptr, int buffer_len, rc4_key *key)
{
    unsigned char x;
    unsigned char y;
    unsigned char *state = NULL;
    unsigned char xorIndex;
    short counter;

    x = key->x;
    y = key->y;

    state = &key->state[0];
    for(counter = 0; counter < buffer_len; counter ++) {
        x = (x + 1) % 256;
        y = (state[x] + y) % 256;
        swap_byte(&state[x], &state[y]);

        xorIndex = (state[x] + state[y]) % 256;<commit_msg>spellfix<commit_after>/*
 * Code is taken from http://www.cypherspace.org/rsa/rc4.html and was adjusted
 * to the style guides and requirements within the CloudRAID project.
 */

#include "rc4.h"

#include <stdlib.h>

LIBEXPORT void swap_byte(unsigned char *a, unsigned char *b)
{
    unsigned char swapByte;

    swapByte = *a;
    *a = *b;
    *b = swapByte;
}

LIBEXPORT void prepare_key(const unsigned char *key_data_ptr, int key_data_len, rc4_key *key)
{
    unsigned char index1;
    unsigned char index2;
    unsigned char *state = NULL;
    short counter;
    unsigned char clean[3072];

    state = &key->state[0];
    for(counter = 0; counter < 256; counter++) {
        state[counter] = counter;
    }
    key->x = 0;
    key->y = 0;
    index1 = 0;
    index2 = 0;
    for(counter = 0; counter < 256; counter++) {
        index2 = (key_data_ptr[index1] + state[counter] + index2) % 256;
        swap_byte(&state[counter], &state[index2]);

        index1 = (index1 + 1) % key_data_len;
    }

    /*
     * It is recommended to use the first 3072 bytes after initializing the key
     */
    for(counter = 0; counter < 3072; counter++) {
        clean[counter] = counter % 256;
    }
    rc4(clean, 3072, key);
}

LIBEXPORT void rc4(unsigned char *buffer_ptr, int buffer_len, rc4_key *key)
{
    unsigned char x;
    unsigned char y;
    unsigned char *state = NULL;
    unsigned char xorIndex;
    short counter;

    x = key->x;
    y = key->y;

    state = &key->state[0];
    for(counter = 0; counter < buffer_len; counter ++) {
        x = (x + 1) % 256;
        y = (state[x] + y) % 256;
        swap_byte(&state[x], &state[y]);

        xorIndex = (state[x] + state[y]) % 256;
{'fraction_non_alphanumeric': 0.13431516936671575, 'fraction_numerical': 0.03829160530191458, 'mean_word_length': 2.6089266737513284, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5342171', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1162, 'n_words': 341}