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

📄 ts.cpp

📁 RSA算法
💻 CPP
字号:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <iostream.h>
#include "Bignum.cpp"

CBigNum GenerateBigRandomNumber(unsigned short nBytes)
{
   CBigNum Result=0U; // 初始化大数
   int i;
   clock_t ctStart;
   unsigned long ctr=0;
   // 设置时间间隔
   clock_t ctInterval = CLOCKS_PER_SEC / 50 + 1; 
   for (i=0; i<nBytes*2; i++)
   {
      ctStart = clock();
	  // 等到大于时间间隔再开始
      while (clock() - ctStart < ctInterval)
         ctr++;
      ctr = (ctr % 33) & 0xF;
      Result <<= 4U; // 大数左移4位
      Result |= ctr; // 做或运算
   }
   putchar('\n');
   return Result; // 返回大数
}

void main()
{
	int  nBytes=32;
	long   end,start=clock();
	double time;

	CBigNum x,e,n,c;
	x=GenerateBigRandomNumber( nBytes);// 生成随机大数
	e=GenerateBigRandomNumber( nBytes);
	n=GenerateBigRandomNumber( nBytes);
    
    c=x.PowMod(e,n);	//作x的e次方mod n的运算

	cout<<"x="<<x<<'\n'<<'\n';
	cout<<"e="<<e<<'\n'<<'\n';
	cout<<"n="<<n<<'\n'<<'\n';
	cout<<"c="<<c<<'\n'<<'\n'<<endl;

	end=clock(); //计时结束
    time=(double)(end-start)/CLOCKS_PER_SEC;
	printf("The time of this operation is:%.3f s",time);
	printf("\n");
}


⌨️ 快捷键说明

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