int main() { rc4_key_t key; rc4_set_key(test_key1, strlen((const char *)test_key1), &key); unsigned char output1[sizeof(test_vec1)] = { 0 }; print_hex_dump_bytes("OUT\t", DUMP_PREFIX_OFFSET, output1, sizeof(output1)); rc4_crypt(output1, sizeof(output1), &key); print_hex_dump_bytes("VEC\t", DUMP_PREFIX_OFFSET, output1, sizeof(output1)); assert(memcmp(test_vec1, output1, sizeof(test_vec1)) == 0); rc4_set_key(test_key2, strlen((const char *)test_key2), &key); unsigned char output2[sizeof(test_vec1)] = { 0 }; print_hex_dump_bytes("OUT\t", DUMP_PREFIX_OFFSET, output2, sizeof(output2)); rc4_crypt(output2, sizeof(output2), &key); print_hex_dump_bytes("VEC\t", DUMP_PREFIX_OFFSET, output2, sizeof(output2)); assert(memcmp(test_vec2, output2, sizeof(test_vec2)) == 0); rc4_set_key(test_key3, strlen((const char *)test_key3), &key); unsigned char output3[sizeof(test_vec1)] = { 0 }; print_hex_dump_bytes("OUT\t", DUMP_PREFIX_OFFSET, output3, sizeof(output3)); rc4_crypt(output3, sizeof(output3), &key); print_hex_dump_bytes("VEC\t", DUMP_PREFIX_OFFSET, output3, sizeof(output3)); assert(memcmp(test_vec3, output3, sizeof(test_vec3)) == 0); printf("passed\n"); return 0; }
int main(int argc, char *argv[]) { if (argc < 3) { return -1; } int i = 0; unsigned char buff[MAX_DATA_LEN]; char *key = argv[1], *data = argv[2]; int key_len = strlen(key); int data_len = strlen(data); memcpy(buff, data, MIN(MAX_DATA_LEN, data_len)); printf("\nKey: "); for (i = 0; i < key_len; i++) { printf("%.2x ", (unsigned char)key[i]); } printf("\n\nPlaintext: "); for (i = 0; i < data_len; i++) { printf("%.2x ", buff[i]); } // encrypt rc4_set_key(&m_ctx, (unsigned char *)key, key_len); rc4_crypt(&m_ctx, buff, data_len); printf("\n\nEncrypted: "); for (i = 0; i < data_len; i++) { printf("%.2x ", buff[i]); } // decrypt rc4_set_key(&m_ctx, (unsigned char *)key, key_len); rc4_crypt(&m_ctx, buff, data_len); printf("\n\nDecrypted: "); for (i = 0; i < data_len; i++) { printf("%.2x ", buff[i]); } printf("\n\n"); return 0; }