


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include #include #include #include #include char s100,*c;intn,e,d,i,c,j,k=0,len;int str100,b30;unsigned gcd(unsigned a, unsigned b )if(a%b=0)return b; elsereturn gcd(b,a%b);void egcd(int a, int b,int &x, int &y)/ax-by=1if(b=0|a=0)x=1; y=0;return ;if(ab)egcd(a,b%a,x,y); x=(int)(b*y+1)/a;elseegcd(a%b
2、,b,x,y);y=(int)(a*x-1)/b;void rsa()int p,q,n,y;printf(请输入素数p和q:);scanf(%d %d,&p,&q); n=p*q;n=(p-1)*(q-1);/printf(n=%d n=%dn,n,n);srand( (unsigned)time( null ) );/初始化随机数while(1)/产生随机整数e,e与n互质e=rand()%n;/printf(e=%dn,e); if(e=0)continue; if(gcd(n,e)=1)break;/printf(e=%dn,e); egcd(e,n,d,y);/ printf(d=%
3、d y=%dn,d,y); printf(公钥pu=e=%d,n=%dn,e,n);printf(私钥pr=d=%d,n=%dn,d,n);void encrypt()/加密函数len=strlen(s);/hgprintf(len=%dn,len);for(i=0;ilen;i+)/去掉s100中的空格if(si122)bk=i; k+;for(j=i;jlen-1;j+)sj=sj+1;len-;slen=0;/结束符printf(密文是:); for(i=0;ilen;i+)c=1;/printf(shiji=%dn,si-97); for(int j=0;je;j+)c=(c*(si-
4、97)%n;/ printf(c=%ldn,c);stri=c;printf(%d,stri);printf(n);void decrypt()/解密函数c=(char*)malloc(len*sizeof(int);for(i=0;ilen;i+)/实现解密c=1;for(int j=0;jd;j+)c=(c*(stri)%n;/ printf(c=%ldn,c);/ printf(c=%dn,c); ci=c+97;ci = 0;/ puts(c);for(int z=0;zk;z+)/加空格for(i=0; ii;j-)cj=cj-1;ci= ;len+; bz+1=bz+1+(z+1)
5、;break;clen = 0;printf(明文:);puts(c);int function()/系统功能选择页面int choice; printf(=n);printf(欢迎进入rsa算法n);printf(1-加密n);printf(2-解密n);printf(3-退出n);printf(=n);printf(请输入要选择的功能号:);scanf(%d,&choice); return choice;int main()int function(); int fc;printf(请输入初始明文(小写):);gets(s);/ puts(s);rsa();/提供私钥和公钥while(1
6、)fc=function();if(fc=1)/加密encrypt();else if(fc=2)/解密decrypt() ; else if(fc=3) break;elseprintf(输入有误,请重新输入!/n);return 0;“”“”at the end, xiao bian gives you a passage. minand once said, people who learn to learn are very happy people. in every wonderful life, learning is an eternal theme. as a profess
7、ional clerical and teaching position, i understand the importance of continuous learning, life is diligent, nothing can be gained, only continuous learning can achieve better self. only by constantly learning and mastering the latest relevant knowledge, can employees from all walks of life keep up with the pace of enterprise development and innovate to meet the needs of the market. this document is also edi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五年度科技产品销售提成及创新激励协议
- 二零二五年度金融机构资金结算服务协议
- 二零二五年度山坪塘承包合同履行中的合同纠纷解决
- 二零二五年度终止双方在线教育平台合作协议
- 二零二五年度海底油气管道水平定向钻施工合作协议
- 二零二五年度全球市场佣金分成合作协议
- 2、2024广西专业技术人员继续教育公需科目参考答案(97分)
- 2025年合作货运从业资格证科目一考试答案
- 预制装配式检查井施工工法
- 公司领导发言稿范文
- 《青春期心理健康指导》课件
- 第18讲 等腰三角形 课件中考数学复习
- 社会阶层与教育选择行为分析-深度研究
- 2025年内蒙古呼和浩特市属国企业纪检监察机构招聘工作人员80人高频重点模拟试卷提升(共500题附带答案详解)
- 社会工作行政(第三版)课件汇 时立荣 第6-11章 项目管理- 社会工作行政的挑战、变革与数字化发展
- 全过程工程咨询文件管理标准
- 模特摄影及肖像使用合同协议范本
- 2025年湘潭医卫职业技术学院高职单招职业适应性测试近5年常考版参考题库含答案解析
- 《预制高强混凝土风电塔筒生产技术规程》文本附编制说明
- 2025福建福州地铁集团限公司运营分公司校园招聘高频重点提升(共500题)附带答案详解
- 儿童睡眠障碍治疗
评论
0/150
提交评论