Example driver showing how to use the Rivest Cipher 4 (RC4) encryption algorithms including the different swap techniques (that do not differ much)
#include <iostream>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
std::cout << "<--------------------------------------------------"
"---->\n\n";
std::cout << "RIVEST CIPHER (RC4) EXAMPLE\n\n";
char *key0 = (char *)"Key";
char *text0 = (char *)"Plaintext";
char *key1 = (char *)"Wiki";
char *text1 = (char *)"pedia";
char *key2 = (char *)"Secret";
char *text2 = (char *)"Attack at dawn";
char *key3 = (char *)"1";
char *text3 = (char *)"username";
int x_swap = 0;
int t_swap = 1;
int b_swap = 2;
unsigned char *hashtext_0 =
(unsigned char *)malloc(sizeof(int) * strlen(text0));
std::cout << "HASHTEXT_0: " << hashtext_0 << std::endl;
printf("String before hash : %s\n", text0);
clock_t a;
a = clock();
unsigned char *computed_text = rc.
compute(key0, text0, hashtext_0, x_swap);
std::cout << "computed_text addr: " << &computed_text << std::endl;
std::string display_text = rc.
store_hash(text0, hashtext_0, x_swap);
std::cout << "COMPUTED HASH(XSWAP) = " << display_text << std::endl;
free(hashtext_0);
a = clock() - a;
double a_time = ((double)a) / CLOCKS_PER_SEC;
printf("a_time = %f sec(s)\n\n", a_time);
printf("String before hash: %s\n", text1);
unsigned char *hashtext_1 =
(unsigned char *)malloc(sizeof(int) * strlen(text1));
clock_t b;
b = clock();
unsigned char *computed_text1 = rc.
compute(key1, text1, hashtext_1, t_swap);
std::cout << "computed_text1 addr: " << &computed_text1 << std::endl;
std::string display_text1 = rc.
store_hash(text1, hashtext_1, t_swap);
std::cout << "COMPUTED HASH (TSWAP) = " << display_text1 << std::endl;
free(hashtext_1);
b = clock() - b;
double b_time = ((double)b) / CLOCKS_PER_SEC;
printf("b_time = %f sec(s)\n\n", b_time);
printf("String before hash: %s\n", text2);
unsigned char *hashtext_2 =
(unsigned char *)malloc(sizeof(int) * strlen(text2));
clock_t c;
c = clock();
unsigned char *computed_text2 = rc.
compute(key2, text2, hashtext_2, b_swap);
std::cout << "computed_text2 addr: " << &computed_text2 << std::endl;
std::string display_text2 = rc.
store_hash(text2, hashtext_2, b_swap);
std::cout << "COMPUTED HASH (BSWAP) = " << display_text2 << std::endl;
free(hashtext_2);
c = clock() - c;
double c_time = ((double)c) / CLOCKS_PER_SEC;
printf("c_time = %f sec(s)\n\n", c_time);
printf("String before hash: %s\n", text3);
unsigned char *hashtext_3 =
(unsigned char *)malloc(sizeof(int) * strlen(text3));
clock_t d;
d = clock();
unsigned char *computed_text3 = rc.
compute(key3, text3, hashtext_3, x_swap);
std::cout << "computed_text2 addr: " << &computed_text3 << std::endl;
std::string display_text3 = rc.
store_hash(text2, hashtext_3, x_swap);
std::cout << "COMPUTED HASH (XSWAP) = " << display_text3 << std::endl;
free(hashtext_3);
d = clock() - d;
double d_time = ((double)d) / CLOCKS_PER_SEC;
printf("d_time = %f sec(s)\n\n", d_time);
return EXIT_SUCCESS;
}
std::string store_hash(char *plaintext, unsigned char *hashtext, int swap_type)
unsigned char * compute(char *key, char *plaintext, unsigned char *hashtext, int swap_type)