Tuesday, 20 June 2017

Basics about Integer class in Crypto++

// refer this documentation - https://www.cryptopp.com/docs/ref/class_integer.html
// http://www.cryptopp.com/docs/ref561/class_integer.html
#include<iostream>
#include<cryptopp/integer.h>
using CryptoPP::Integer;
using std::cout;
using std::endl;

int main()
{
	// example showing calculation of 2^x for really big x
	cout<<"2**30000 = "<<Integer::Power2(30000)<<endl; // Power2 is a static member function of class. 
	

	// addition, subtraction, multiplication, division of two big numbers
	Integer i1=Integer::Power2(100); 
	Integer i2=Integer::Power2(50);

	cout<<"2**100 + 2**50 = "<<i1+i2<<endl;
	cout<<"2**100 - 2**50 = "<<i1-i2<<endl;
	cout<<"2**100 * 2**50 = "<<i1*i2<<endl;
	cout<<"2**100 / 2**50 = "<<i1/i2<<endl;
	
	// example showing use of modular operator
	Integer i3=Integer::Power2(1024);
	Integer i4(501);

	cout<<"2**1024 % 501 = "<<i3%i4<<endl;

	// example showing calculation of modular inverse
	Integer i5(3628800);
	Integer i6(2431);
	cout<<"modular inverse of 3628800 wrt 2431 = "<<i5.InverseMod(i6)<<endl;
	
	// example showing GCD of two numbers
	cout<<"GCD("<<i5<<","<<i6<<") = "<<Integer::Gcd(i5,i6)<<endl;

	Integer a,b,c;
	a=Integer(10241024);
	b=Integer(10241024);
	c=Integer(1000000007);

	// modular Multiplication 
	cout<<a_times_b_mod_c(a,b,c)<<endl;
	// modular Exponentiation
	cout<<a_exp_b_mod_c(a,b,c)<<endl;


	return 0;
}


No comments:

Post a Comment