int main(int argc, char*argv[]){ paillier_pubkey_t *pubkey; paillier_prvkey_t *privkey; paillier_ciphertext_t ciphertext_input; paillier_plaintext_t output; mpz_init(ciphertext_input.c); mpz_init(output.m); pubkey = paillier_pubkey_from_hex("8b7401f20812b8a58678f4c9f73f3b7f"); privkey = paillier_prvkey_from_hex("45ba00f904095c520637a615b99fb088",pubkey); if(argc == 2){ mpz_set_str(ciphertext_input.c, argv[1], BASE); paillier_dec(&output, pubkey, privkey, &ciphertext_input); unsigned long dec_res = mpz_get_ui(output.m); printf("%lu\n",dec_res); return dec_res; } else if(argc>2){ printf("Too many inputs.\n"); return 1; } else{ printf("Need at least one input.\n"); return 1; } }
int main(int argc, char * argv[]){ // encrypt input numeric value paillier_pubkey_t *pubkey; paillier_prvkey_t *privkey; paillier_ciphertext_t ciphertext1; mpz_init(ciphertext1.c); int input_v; sscanf (argv[1],"%d",&input_v); if (argc == 2) { pubkey = paillier_pubkey_from_hex("8b7401f20812b8a58678f4c9f73f3b7f"); // privkey = paillier_prvkey_to_hex("45ba00f904095c520637a615b99fb088"); paillier_plaintext_t* input1 = paillier_plaintext_from_ui(input_v); // gmp_printf("Here is the original value one: %Zd\n", input1->m); paillier_enc(&ciphertext1, pubkey, input1, &paillier_get_rand_devurandom); char * encrypted_res= mpz_get_str(NULL, BASE, ciphertext1.c); printf("%s\n", encrypted_res); return 0; } else if (argc >2){ printf("Too many input.\n"); return 1; } else{ printf("One argument expected.\n"); return 1; } }
int main (int argc, char* argv[]){ //aillier_plaintext_t* amt = paillier_plaintext_from_ui( atoi(argv[1])); paillier_pubkey_t* publicKey; publicKey = paillier_pubkey_from_hex("91b6a0c0e8374bac6d4e75f2497ff89f") ; unsigned int salary = strtoul(argv[1], NULL, 0); paillier_plaintext_t* amt = paillier_plaintext_from_ui( salary); paillier_ciphertext_t* encr; encr = paillier_enc(NULL, publicKey,amt,paillier_get_rand_devurandom); char* result_string = mpz_get_str(NULL, 10, encr->c); printf("%s\n",result_string); return 0; }