一个简单的公私钥加密算法

#include 
#include 
#include 

using namespace std;
struct public_key
{
	int  n;
	int  x;
};
struct private_key
{
	int p;
	int q;
};
int  power(int x,int y,int m)//cal x^y%m
{
	if(y==0)return 1%m;
	int  ret=x%m;
	for(int i=0;in=p*q;
	bk->x=get_x(p,q);
	rk->p=p;
	rk->q=q;
}
int get_random(int n)
{
	srand(unsigned(time(0)));
	int ret=rand()%1000;
	int max,min;
	if(ret>=n)
	{
		max=ret;
		min=n;
	}
	else 
	{
		max=n;
		min=ret;
	}
	while(min)
	{
		int tmp=max%min;
		if(tmp==1)return  ret;
		max=min;
		min=tmp;
	}
}
int encrypt(int src,int n,int x)
{
	int y=get_random(n);
	cout<<"get y:"<n,bk->x);
	cout<<"encrypt:"<p,rk->q)<n,bk->x);
	cout<<"encrypt:"<p,rk->q)<

你可能感兴趣的:(一个简单的公私钥加密算法)