21 std::cout <<
"<--------------------------------------------------"
23 std::cout <<
"RIVEST CIPHER (RC4) EXAMPLE\n\n";
36 char *key0 = (
char *)
"Key";
37 char *text0 = (
char *)
"Plaintext";
39 char *key1 = (
char *)
"Wiki";
40 char *text1 = (
char *)
"pedia";
42 char *key2 = (
char *)
"Secret";
43 char *text2 = (
char *)
"Attack at dawn";
45 char *key3 = (
char *)
"1";
46 char *text3 = (
char *)
"username";
61 unsigned char *hashtext_0 =
62 (
unsigned char *)malloc(
sizeof(
int) * strlen(text0));
64 std::cout <<
"HASHTEXT_0: " << hashtext_0 << std::endl;
65 printf(
"String before hash : %s\n", text0);
74 unsigned char *computed_text = rc.
compute(key0, text0, hashtext_0, x_swap);
75 std::cout <<
"computed_text addr: " << &computed_text << std::endl;
79 std::string display_text = rc.
store_hash(text0, hashtext_0, x_swap);
80 std::cout <<
"COMPUTED HASH(XSWAP) = " << display_text << std::endl;
85 double a_time = ((double)a) / CLOCKS_PER_SEC;
86 printf(
"a_time = %f sec(s)\n\n", a_time);
88 printf(
"String before hash: %s\n", text1);
89 unsigned char *hashtext_1 =
90 (
unsigned char *)malloc(
sizeof(
int) * strlen(text1));
95 unsigned char *computed_text1 = rc.
compute(key1, text1, hashtext_1, t_swap);
96 std::cout <<
"computed_text1 addr: " << &computed_text1 << std::endl;
97 std::string display_text1 = rc.
store_hash(text1, hashtext_1, t_swap);
98 std::cout <<
"COMPUTED HASH (TSWAP) = " << display_text1 << std::endl;
102 double b_time = ((double)b) / CLOCKS_PER_SEC;
103 printf(
"b_time = %f sec(s)\n\n", b_time);
105 printf(
"String before hash: %s\n", text2);
106 unsigned char *hashtext_2 =
107 (
unsigned char *)malloc(
sizeof(
int) * strlen(text2));
111 unsigned char *computed_text2 = rc.
compute(key2, text2, hashtext_2, b_swap);
112 std::cout <<
"computed_text2 addr: " << &computed_text2 << std::endl;
113 std::string display_text2 = rc.
store_hash(text2, hashtext_2, b_swap);
114 std::cout <<
"COMPUTED HASH (BSWAP) = " << display_text2 << std::endl;
118 double c_time = ((double)c) / CLOCKS_PER_SEC;
119 printf(
"c_time = %f sec(s)\n\n", c_time);
122 printf(
"String before hash: %s\n", text3);
123 unsigned char *hashtext_3 =
124 (
unsigned char *)malloc(
sizeof(
int) * strlen(text3));
128 unsigned char *computed_text3 = rc.
compute(key3, text3, hashtext_3, x_swap);
129 std::cout <<
"computed_text2 addr: " << &computed_text3 << std::endl;
130 std::string display_text3 = rc.
store_hash(text2, hashtext_3, x_swap);
131 std::cout <<
"COMPUTED HASH (XSWAP) = " << display_text3 << std::endl;
135 double d_time = ((double)d) / CLOCKS_PER_SEC;
136 printf(
"d_time = %f sec(s)\n\n", d_time);
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)