Tuesday, 20 June 2017

Integer XOR in Crypto++

#include<iostream>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

#include<cryptopp/integer.h>
using CryptoPP::Integer;


Integer XOR(Integer &a,Integer &b)
{
	Integer result=0;
	if(a>b)
	{
		for(int i=a.BitCount()-1;i>=b.BitCount();i--)
			result=result*2 + a.GetBit(i);
		for(int i=b.BitCount()-1;i>=0;i--)
			result=result*2 + (a.GetBit(i) ^ b.GetBit(i));
	}
	else
	{
		for(int i=b.BitCount()-1;i>=a.BitCount();i--)
			result=result*2 + b.GetBit(i);
		for(int i=a.BitCount()-1;i>=0;i--)
			result=result*2 + (a.GetBit(i) ^ b.GetBit(i));
	}

	return result;
}
void printBits(Integer &a)
{	
	for(int i=a.BitCount()-1;i>=0;i--)
		cout<<a.GetBit(i);
	cout<<endl;
}
int main()
{
	int x,y;
	cin>>x>>y;
	Integer a(Integer::Power2(x));
	Integer b(Integer::Power2(y));

	cout<<XOR(a,b)<<endl;
	return 0;
}



No comments:

Post a Comment