Modular exponentiation with a secret exponent is a frequently used operation inp
ID: 3681777 • Letter: M
Question
Modular exponentiation with a secret exponent is a frequently used operation inpublic-key cryptography. Suppose we have fixed a (large) prime number p and agenerator g {2,…,p1} of a multiplicative subgroup of GF(p)*. The order of g istypically a large prime number (which divides p1).
Write a program, or pseudo code, for a function that obtains as input three non-negative integers: p and g as just described and a non-negative exponent x. The function must return gx mod p. Your function must be able to handle x-values as larg eas 22000, and (having in mind timing attacks) the number of multiplications that are performed by your function must not depend on x.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<math.h>
using namespace std;
int generateKey(int,int,int);
int main()
{
int g,p,x;
cout<<"enter the value for p";
cin>>p;
cout<<"enter the value for g";
cin>>g;
cout<<"enter the value for exponent x";
cin>>x;
int key;
key= generateKey(p,g,x);
cout<<"the public key cryptography is:"<<key;
return 0;
}
int generateKey(int p, int g, int x)
{
int k,k1;
k=pow(g,x);
k1= k%p;
return k1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.