91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 6KB
    文件類型: .java
    金幣: 1
    下載: 1 次
    發(fā)布日期: 2021-10-03
  • 語言: Java
  • 標簽: RSA??

資源簡介

java實現(xiàn)簡單RSA 公鑰密碼系統(tǒng) 源代碼(有界面)

資源截圖

代碼片段和文件信息

package?basicMath;

import?java.awt.FlowLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.util.ArrayList;
import?java.util.Random;

import?javax.swing.JButton;
import?javax.swing.Jframe;
import?javax.swing.JLabel;
import?javax.swing.JPanel;
import?javax.swing.JTextField;

public?class?RSA{
static?int?p;
static?int?q;
static?int?e;
static?int?d;
static?int?n;
static?int?n2;

//返回模M進制的逆序
static?ArrayList?binary(int?xint?m)?{
ArrayList?at?=?new?ArrayList();
int?a?=?0;
while(x>m||x?==?m)?{
a=?x%m;
at.add(a);
x?=?x/m;
}
at.add(x);
return?at;
}

//返回x模m的逆原
static?int?euclid(int?x?int?m)?{
int?s0?=?1s1?=?0;
int?a?=?x%mb?=?0;
while(a>1)?{
a?=?x%m;
b?=?x/m;
x?=?m;
m?=?a;
int?temp?=?s1;
s1?=?s0?-?b*s1;
s0?=?temp;
}
return?s1;
}

//模重復(fù)平方
static?int?powMod(int?xint?vint?h)?{
String?s?=?Integer.toBinaryString(v);
char[]?s1?=?s.toCharArray();
int?a?=?1;
int?b?=?x?%h;
for(int?i?=?s1.length-1;i>-1;i--)?{
if(s1[i]?==?‘1‘)?{
a?=?(a*b)%h;
b?=?(b*b)%h;
}else?{
b?=?(b*b)%h;
}
}
return?a;
}

//獲取隨機素數(shù)
static?int?get_number()?{
Random?random?=?new?Random();?
int?temp?=?random.nextInt(20)+3;
int?flag?=?1;
for(int?i=2;i if(temp%i==0)?{
flag?=?0;
break;
}
}
if(flag?==?1)
return?temp;
else
return?get_number();
}

//獲取隨機pq的值
static?void?get_pq()?{
p?=?get_number();
q?=?get_number();
while(p?==?q)?{
q?=?get_number();
}
n?=?p*q;
n2?=?(p-1)*(q-1);
}

//獲取隨機e的值
static?void?get_e()?{
Random?random?=?new?Random();
e?=?random.nextInt(20)+11;
if(e>n2||e==n2){
get_e();
}
}

//獲取d的值
static?void?get_d()?{
d?=?euclid(en2);
if(d<0)?{
get_e();
get_d();
}
}

//整型轉(zhuǎn)字符型
static?char?intTochar(int?t)?{
char?c?=?(char)?t;
return?c;
}

//字符型轉(zhuǎn)整型
static?int?charToint(char?t?)?{
int?i?=?t;
return?i;
}

//加密函數(shù),返回加密后的密文
static?String?encrypt(String?words){
char[]?temp?=?words.toCharArray();
int[]?tempint?=?new?int[words.length()];
for(int?i?=0;i if(charToint(temp[i])<97)?{
temp[i]?=?intTochar(charToint(temp[i])+32);
}
int?g?=?charToint(temp[i])-97;
tempint[i]?=?g;
}

ArrayList?a?=?new?ArrayList();
int?t?=?tempint[0];
int?t2?=?1;
while(t2 while?(t*26+tempint[t2] t?=?t*26+tempint[t2];
t2++;
if(t2>tempint.length-1)
break;
}
a.add(powMod(ten?));
if(t2 t?=?tempint[t2];
t2++;
if(t2?==?tempint.length)?{
a.add(powMod(ten));
}
}
}
StringBuffer?sb?=?new?StringBuffer();
ArrayList?tempList?=?new?ArrayList();
for(int?i?=?0;i

評論

共有 條評論