69 uint32_t len = strlen(key);
77 j = (j + S[i] + key[i % len]) &
BITS;
81 XOR_swap(&S[i], &S[j]);
82 }
else if (swap_type == 1) {
83 trad_swap(&S[i], &S[j]);
84 }
else if (swap_type == 2) {
85 byte_swap(&S[i], &S[j]);
92 unsigned char *ciphertext,
97 for (
size_t n = 0, len = strlen(plaintext); n < len; n++) {
99 j = (j + S[i]) &
BITS;
102 if (swap_type == 0) {
103 XOR_swap(&S[i], &S[j]);
104 }
else if (swap_type == 1) {
105 trad_swap(&S[i], &S[j]);
106 }
else if (swap_type == 2) {
107 byte_swap(&S[i], &S[j]);
110 uint32_t rnd = S[(S[i] + S[j]) &
BITS];
112 ciphertext[n] = rnd ^ plaintext[n];
119 size_t len = strlen((
char *)plaintext);
121 char buffer[len + 1];
122 size_t size =
sizeof(buffer);
125 std::string stored_text =
"";
128 for (
size_t index = 0; index < len; index++) {
129 if (swap_type == 0) {
130 snprintf(buffer, size,
"|x%02hhx|", hashtext[index]);
134 snprintf(buffer, size,
"%02hhX", hashtext[index]);
137 stored_text += std::string(buffer);
144 unsigned char *ciphertext,
146 if (ciphertext == NULL) {
147 throw std::runtime_error(
"[-] Error Allocating Memory");
151 if (0 <= swap_type && swap_type <= 2) {
153 KSA(key, S, swap_type);
154 PRGA(S, plaintext, ciphertext, swap_type);
157 else if (swap_type > 2) {
158 throw std::runtime_error(
"[-] Invalid swap_type");
void PRGA(unsigned char *S, char *plaintext, unsigned char *ciphertext, int swap_type)
std::string store_hash(char *plaintext, unsigned char *hashtext, int swap_type)
void XOR_swap(unsigned char *a, unsigned char *b)
void byte_swap(uint8_t *a, uint8_t *b)
void trad_swap(unsigned char *a, unsigned char *b)
unsigned char * compute(char *key, char *plaintext, unsigned char *hashtext, int swap_type)
void KSA(char *key, unsigned char *S, int swap_type)