收藏 分销(赏)

RSA算法实验报告.doc

上传人:丰**** 文档编号:4328966 上传时间:2024-09-06 格式:DOC 页数:18 大小:81.92KB
下载 相关 举报
RSA算法实验报告.doc_第1页
第1页 / 共18页
RSA算法实验报告.doc_第2页
第2页 / 共18页
RSA算法实验报告.doc_第3页
第3页 / 共18页
RSA算法实验报告.doc_第4页
第4页 / 共18页
RSA算法实验报告.doc_第5页
第5页 / 共18页
点击查看更多>>
资源描述

1、实验二 非对称密码算法RSA一、实验目的通过实际编程了解非对称密码算法RSA的加密和解密过程,加深对非对称密码算法的认识。二、实验环境运行Windows或Linux操作系统的PC机,具有JDK1.6版本的Java语言编译环境。三、实验内容和步骤1. 对RSA算法的理解RSA算法(公开密钥算法)的原理:(1) 选择两个大的素数p和q(典型情况下为1024位)(2) 计算n = p * q 和 z =(p-1)*(q-1).(3) 选择一个与z互素的数,将它称为d(4) 找到e,使其满足e*d = 1 mod z提前计算出这些参数以后,我们就可以开始执行加密了。首先将明文分成块,使得每个明文消息P

2、落在间隔0*Pn中。为了做到这一点,只要将明文划分成k位的块即可,这里k是满足2k=0;-i) if(infileName.charAt(i)=.) break; String outfileName = infileName.substring(0,i); outfileName = outfileName + new String(.EncodeRsa) + infileName.substring(i,infileName.length(); PublicMethod.output(outfileName,outStr); private JTextField P; private JT

3、extField Q; private JTextField E; private JTextField D; private Frame fr; int i; class FileDecodeListener implements ActionListener public FileDecodeListener(Frame f,JTextField ap, JTextField aq,JTextField ae,JTextField ad) P = ap; Q = aq; E = ae; D = ad; fr = f; public void actionPerformed(ActionEv

4、ent ee) FileDialog fd = new FileDialog(fr); fd.setVisible(true); String infileName =fd.getDirectory()+fd.getFile(); String inStr = new String(); inStr = PublicMethod.input(infileName); System.out.println(inStr); BigInteger PrimeP = new BigInteger(P.getText(); BigInteger PrimeQ = new BigInteger(Q.get

5、Text(); BigInteger n =PrimeP.multiply(PrimeQ); int nLen = n.bitLength(); int m=(int)(Math.ceil(double)(nLen)/16.0); nLen = (nLen-1) / 16; String outStr = new String(); outStr = PublicMethod.Decode(inStr,PrimeP,PrimeQ,n,nLen,m,E); for(i=infileName.length()-1;i=0;-i) if(infileName.charAt(i)=.) break;

6、String outfileName = infileName.substring(0,i); outfileName = outfileName + new String(.DecodeRsa) + infileName.substring(i,infileName.length(); PublicMethod.write(outfileName,outStr); private JTextField P; private JTextField Q; private JTextField E; private JTextField D; private Frame fr; int i; cl

7、ass RandListener implements ActionListener public RandListener(JTextField aP, JTextField aQ) P = aP; Q = aQ; public void actionPerformed(ActionEvent e) PublicMethod.GetPrime( P ); PublicMethod.GetPrime( Q ); private JTextField P; private JTextField Q; class RandDListener implements ActionListener pu

8、blic RandDListener(JTextField aP, JTextField aQ, JTextField ad, JTextField ae) P = aP; Q = aQ; d = ad; e = ae; public void actionPerformed(ActionEvent ee) BigInteger PP = new BigInteger(P.getText(); BigInteger QQ = new BigInteger(Q.getText(); BigInteger temp = (PP.subtract(new BigInteger(1).multiply

9、(QQ.subtract(new BigInteger(1); BigInteger temp1; do temp1=new BigInteger(100, new Random().mod(temp); while(PublicMethod.MillerRobin(temp1)=false); d.setText(temp1.toString(); e.setText(PublicMethod.invmod(temp1, temp).toString(); private JTextField P; private JTextField Q; private JTextField d; pr

10、ivate JTextField e; class EncodeListener implements ActionListener public EncodeListener(JTextField aP, JTextField aQ, JTextField ad, JTextField ae, JTextArea in, JTextArea out) P = aP; Q = aQ; d = ad; e = ae; input = in; output = out; public void actionPerformed(ActionEvent ee) BigInteger PrimeP =

11、new BigInteger(P.getText(); BigInteger PrimeQ = new BigInteger(Q.getText(); BigInteger n =PrimeP.multiply(PrimeQ); int nLen = n.bitLength(); int m=(int)(Math.ceil(double)(nLen)/16.0); nLen = (nLen-1) / 16; String inStr = input.getText(); output.setText(PublicMethod.Encode(inStr,PrimeP,PrimeQ,n,nLen,

12、m,e); private JTextField P; private JTextField Q; private JTextField d; private JTextField e; private JTextArea input; private JTextArea output; class DecodeListener implements ActionListener public DecodeListener(JTextField aP, JTextField aQ, JTextField ad, JTextField ae, JTextArea out, JTextArea o

13、ut1) P = aP; Q = aQ; d = ad; e = ae; output = out; output1 = out1; public void actionPerformed(ActionEvent ee) BigInteger PrimeP = new BigInteger(P.getText(); BigInteger PrimeQ = new BigInteger(Q.getText(); BigInteger n =PrimeP.multiply(PrimeQ); int nLen = n.bitLength(); int m=(int)(Math.ceil(double

14、)(nLen)/16.0); nLen = (nLen-1) / 16; String inStr = output.getText(); output1.setText(PublicMethod.Decode(inStr,PrimeP,PrimeQ,n,nLen,m,d); private JTextField P; private JTextField Q; private JTextField d; private JTextField e; private JTextArea output; private JTextArea output1; class PublicMethod public static void GetPrime( JTextField prime ) BigInteger num = new BigInteger(0); Random rand = new Random(); do int length = (int)(Math.random()*20+100); System.out.println(length); num = new BigInteger( length, 5 , rand ); prime.setText(num.toString(); while(MillerRobin(num)=false); pu

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
百度文库年卡

猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服