1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <iostream>
#include <math.h>
#include <cctype>
#include <string.h>
#include <stdio.h>
#include <gmp.h>
using namespace std;
int chartonum(char letter)
{
int result;
result = (int)letter;
return result;
}
int main()
{
mpz_t key, e, ciphertext[30], value, value2, prime1, prime2;
mpz_init(key);
mpz_init_set_ui(e,19);
mpz_array_init(ciphertext[0],30,512);
mpz_init(value);
mpz_init(value2);
mpz_init_set_ui(prime1,7151);
mpz_init_set_ui(prime2,8293);
mpz_mul(key, prime1, prime2);
string plaintext;
bool run=true;
cout.precision(20);
while(run){
cin >> plaintext;
for(int i=0;i<plaintext.length();i++)
{
mpz_set_ui(value, chartonum(plaintext[i]));
mpz_powm(ciphertext[i], e, value, key);
cout << ciphertext[i] << endl;
}
}
return 0;
}
| |