⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myrsa.cpp

📁 椭圆曲线密码C实现的
💻 CPP
字号:
// Myrsa.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "conio.h"
#include "rsa.h"
#include "time.h"

unsigned char	*pBuf;
unsigned		*pMov;

int MDFile (char *filename,int nMaxLen);

int WriteFile (unsigned char *pBuf,int nLen);
int main(int argc, char* argv[])
{
	vlong out1,out2,out3,out4,out5;
	int o,oo = out1;
	clock_t start,end;		
	out1 = 12412349;
	out4 = out1;
	out5 = vlong(100000);

	start = clock();
	out3 = modexp(out4,198001,100000);
	end = clock() - start;	
	printf("end1: %d\n",end);
	start = clock();
	o = out3;
	for(int i = 0;i<198000;i++)
	{
		out1 = out1*vlong(12412349);
//		out1 = 12412349;
		out1 = out1%out5;
//		if(out1>out5)
//			;
//		out1 = out5;
//		out1/out5;
//		vlong xx;
	}

	oo = out1;

	end = clock() - start;	
	printf("end2: %d\n",end);
	getch();
	out4 = out1;
	vlong	a;
	vlong	b;
	vlong	c ;
	a = 3;
	b = 10;
	c =  modinv( a , b ) ;
	int x = c;

	pBuf	=	new unsigned char[1024*50];
	pMov	=	(unsigned *)pBuf;

	/*
	pBuf[0] = 'A';
	pBuf[1] = 'B';
	pBuf[2] = 'C';
	pBuf[3] = 'D';
	*/
	int nLen = MDFile("c:\\test.txt",1024);
	int nRem = nLen%4;

	nLen =  (nRem != 0) ? nLen+(4-nRem):nLen ;

	char	r1[] = {"A"};//CDEFGHIJKLMON
	char	r2[] = {"C"};//34567890
	
	private_key		thePrivateKey;	
	prime_factory	thePrimeFactory;
	thePrivateKey.create(r1,r2);
	unsigned int	m,e;
	unsigned int	p,q;
	vlong	thePlain;
	vlong	tmp;
	vlong	theResult;

	m = thePrivateKey.m;
	e = thePrivateKey.e;
	p = thePrivateKey.p;
	q = thePrivateKey.q;

	thePlain = *pMov;

	pMov	=	(unsigned *)pBuf;//
	for(i = 0;i<nLen;i+=4)
	{
		thePlain = *pMov;
		tmp	= thePrivateKey.encrypt(thePlain);	//*pMov
		*pMov = tmp ;	//
		pMov ++;
	}

	pMov	=	(unsigned *)pBuf;//
	for(i = 0;i<nLen;i+=4)
	{
/*		thePlain = tmp;
		thePlain -= thePlain;
*/
	     thePlain  = *pMov;
		*pMov = thePrivateKey.decrypt(thePlain);	
		pMov ++;
	}
	pMov	=	(unsigned *)pBuf;//
	nLen =  (nRem != 0) ? nLen-4+nRem:nLen ;

	WriteFile ( pBuf, nLen );
/*
	
	thePlain = thePrivateKey.encrypt(thePlain);	
	theResult = thePrivateKey.decrypt(thePlain);
	*pMov = theResult;
	printf("%c%c%c%c\n",pBuf[0],pBuf[1],pBuf[2],pBuf[3]);
*/

	if(pBuf !=NULL)
		delete []pBuf;
	
	getch();
	return 0;
}

int MDFile (char *filename,int nMaxLen)
{
	FILE *file;
	int len;

	if ((file = fopen (filename, "rb")) == NULL)
	{
		printf ("%s can't be opened\n", filename);	  
	}else {

		len = fread (pBuf, 1, nMaxLen, file);
		fclose (file);	  
		printf ("Opened the %s.\n",filename);
	}

	return len;
}

int WriteFile (unsigned char *pBuf,int nLen)
{
	FILE	*fo;
	char *cp;	
	int c;
	if((fo = fopen("c:\\test_out.txt","r")) == NULL)
	{
		fo = fopen("c:\\test_out.txt","w+");
	}
	fwrite(pBuf,1,nLen,fo);
	fclose(fo);
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -