📄 code.java
字号:
subwin.setVisible(true);
subwin.validate();
}
}
class ListsetAction extends AbstractAction
{
public ListsetAction()
{
super("查表加密");
}
char checkcon(char a)
{
int i,j;
for(i=0;i<54;i++)
if(list[i]==a)
break;
j=(i+Listlength)%54;
return list[j];
}
void setcode()
{
int i;
String te=new String("");
char temp[]=textPane.getText().toCharArray();
for(i=0;i<textPane.getText().length();i++)
{
te=te+checkcon(temp[i]);
}
textPane.setText(te);
}
public void actionPerformed(ActionEvent e)
{
if(listflag)
{
new Warning("提示","加密中.....");
try{
setcode();
new Warning("提示","加密成功,请保存");
new Saveing();
listflag=false;
}
catch(Exception E)
{
new Warning("提示","加密异常,请重新加密");
}
}
else
{
new Warning("警告","为了信息安全请重新设置加密步长");
}
}
}
class ListopenAction extends AbstractAction
{
public ListopenAction()
{
super("查表解密");
}
char checkcon(char a)
{
int i,j;
for(i=0;i<54;i++)
if(list[i]==a)
break;
j=(i-Listlength+54)%54;
return list[j];
}
void opencode()
{
int i;
String te=new String("");
char temp[]=textPane.getText().toCharArray();
for(i=0;i<textPane.getText().length();i++)
{
te=te+checkcon(temp[i]);
}
textPane.setText(te);
}
public void actionPerformed(ActionEvent e)
{
subwin=new JDialog();
subwin.setTitle("输入解密钥匙");
subwin.setModal(true);
subwin.setBounds(320,150,200,140);
text1=new JTextField(8);
subwin.add(new JLabel("设置解密步长"));
subwin.add(text1);
subwin.add(button6);
subwin.add(button2);
FlowLayout flow=new FlowLayout();
subwin.setLayout(flow);
subwin.setVisible(true);
subwin.validate();
if(listopenflag)
{
new Warning("提示","解密中.....");
try{
opencode();
new Warning("提示","解密成功,请保存");
new Saveing();
listopenflag=false;
}
catch(Exception E)
{
new Warning("提示","解密异常,请重新解密");
}
}
else
{
new Warning("警告","尚未设置解密钥匙");
}
}
}
class ReplacesetwordAction extends AbstractAction
{
public ReplacesetwordAction()
{
super("设置替换词");
}
public void actionPerformed(ActionEvent e)
{
subwin=new JDialog();
subwin.setTitle("设置替换词a->?");
subwin.setModal(true);
subwin.setBounds(320,150,300,120);
text1=new JTextField(8);
subwin.add(new JLabel("设置替换词要求不相同"));
subwin.add(text1);
subwin.add(button7);
subwin.add(button2);
FlowLayout flow=new FlowLayout();
subwin.setLayout(flow);
subwin.setVisible(true);
subwin.validate();
}
}
class ReplacesetAction extends AbstractAction
{
public ReplacesetAction()
{
super("替换加密");
}
void setcode()
{
char codete[]=textPane.getText().toCharArray();
char oldco[]=replacecode.toCharArray();
String codeser=new String();
int clen=textPane.getText().length();
int tlen=replacecode.length();
int hlen;
int i,j,k,l,sa;
hlen=clen/tlen;
if(clen%tlen!=0)
++hlen;
int index[];
index=new int[tlen];
char listcode[][];
char tp;
listcode=new char[hlen][tlen];
for(k=0;k<tlen;k++)
{
tp=oldco[k];
sa=0;
for(l=0;l<tlen;l++)
if((oldco[l]<tp)&&k!=l)
++sa;
index[sa]=k;
}
for(j=0;j<clen;j++)
{
listcode[j/tlen][j%tlen]=codete[j];
}
for(i=0;i<tlen;i++)
{
for(j=0;j<hlen;j++)
{
codeser=codeser+listcode[j][index[i]];
}
}
textPane.setText(codeser);
}
public void actionPerformed(ActionEvent e)
{
if(replacesetflag)
{
new Warning("提示","加密中.....");
try{
setcode();
new Warning("提示","加密成功,请保存");
new Saveing();
replacesetflag=false;
}
catch(Exception E)
{
new Warning("提示","加密异常,请重新加密");
}
}
else
{
new Warning("警告","为了信息安全请重新设置加密单词");
}
}
}
class ReplaceopenAction extends AbstractAction
{
public ReplaceopenAction()
{
super("替换解密");
}
void opencode()
{
char codete[]=textPane.getText().toCharArray();
char oldco[]=replacecode.toCharArray();
int clen=textPane.getText().length();
int tlen=replacecode.length();
int index[];
int i,j,k,l,sa;
int hlen;
index=new int[tlen];
hlen=clen/tlen;
if(clen%tlen!=0)
++hlen;
char listcode[][];
char tp;
String tp1=new String("");
listcode=new char[hlen][tlen];
for(k=0;k<tlen;k++)
{
tp=oldco[k];
sa=0;
for(l=0;l<tlen;l++)
if((oldco[l]<tp)&&k!=l)
++sa;
index[sa]=k;
}
for(i=0,j=0;i<clen;i=i+hlen)
{
for(k=0;k<hlen;k++)
listcode[k][index[j]]=codete[i+k];
++j;
}
for(i=0;i<hlen;i++)
{
for(j=0;j<tlen;j++)
tp1=tp1+listcode[i][j];
}
textPane.setText(tp1);
}
public void actionPerformed(ActionEvent e)
{
subwin=new JDialog();
subwin.setTitle("输入解密单词");
subwin.setModal(true);
subwin.setBounds(320,150,200,140);
text1=new JTextField(8);
subwin.add(new JLabel("设置解密单词"));
subwin.add(text1);
subwin.add(button8);
subwin.add(button2);
FlowLayout flow=new FlowLayout();
subwin.setLayout(flow);
subwin.setVisible(true);
subwin.validate();
if(replaceopenflag)
{
new Warning("提示","解密中.....");
try{
opencode();
new Warning("提示","解密成功,请保存");
new Saveing();
replaceopenflag=false;
}
catch(Exception E)
{
new Warning("提示","解密异常,请重新解密");
}
}
else
{
new Warning("警告","尚未设置解密单词");
}
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
try{
if(checkformat(text1.getText()))
{
x=Integer.parseInt(text1.getText());
if(x<20||x>1000)
{ new Warning("警告","参数小于20或大于1000");text1.setText("");}
else
{
rsasetflag=true;
subwin.setVisible(false);
}
}
else
{
new Warning("警告对话框 ","输入非法字符");
text1.setText("");
}
}
catch(Exception E)
{
text1.setText("");
new Warning("警告","必须输入");
}
}
if(e.getSource()==button2)
{
subwin.setVisible(false);
}
if(e.getSource()==button3)
{int n,d;
try{
if(checkformat(text1.getText())&&checkformat(text2.getText()))
{
n=Integer.parseInt(text1.getText());
d=Integer.parseInt(text2.getText());
if(n<d)
new Warning("警告","输入非法n<d");
else
{
coden=n;
coded=d;
rsacodeflag=true;
subwin.setVisible(false);
}
}
else
{
new Warning("警告对话框 ","输入非法字符");
text1.setText("");
text2.setText("");
}
}
catch(Exception E)
{
text1.setText("");
text2.setText("");
new Warning("警告","必须输入");
}
}
if(e.getSource()==button4)
{ int n,e1;
try{
if(checkformat(text1.getText())&&checkformat(text2.getText()))
{
n=Integer.parseInt(text1.getText());
e1=Integer.parseInt(text2.getText());
// if(n<e1)
// new Warning("警告","输入非法n<e");
// else
// {
coden=n;
codee=e1;
rsaopenflag=true;
subwin.setVisible(false);
// }
}
else
{
new Warning("警告对话框 ","输入非法字符");
text1.setText("");
text2.setText("");
}
}
catch(Exception E)
{
text1.setText("");
text2.setText("");
new Warning("警告","必须输入");
}
}
if(e.getSource()==button5)
{ int temp;
try{
if(checkformat(text1.getText()))
{
temp=Integer.parseInt(text1.getText())%54;
if(temp==0)
new Warning("警告","输入非法n!=0");
else
{
Listlength=temp;
listflag=true;
subwin.setVisible(false);
}
}
else
{
new Warning("警告对话框 ","输入非法字符");
text1.setText("");
}
}
catch(Exception E)
{
text1.setText("");
new Warning("警告","必须输入");
}
}
if(e.getSource()==button6)
{
int temp1;
try{
if(checkformat(text1.getText()))
{
temp1=Integer.parseInt(text1.getText())%54;
if(temp1==0)
new Warning("警告","输入非法n!=0");
else
{
Listlength=temp1;
listopenflag=true;
subwin.setVisible(false);
}
}
else
{
new Warning("警告对话框 ","输入非法字符");
text1.setText("");
}
}
catch(Exception E)
{
text1.setText("");
new Warning("警告","必须输入");
}
}
if(e.getSource()==button7)
{
int i,j;
char temp2[]=text1.getText().toCharArray();
try{
if(text1.getText().length()==0)
new Warning("警告","必须输入");
else
{
for(i=0;i<text1.getText().length();i++)
{
for(j=0;j<text1.getText().length();j++)
if((temp2[i]==temp2[j])&&i!=j)
break;
if(j!=text1.getText().length())
break;
}
if(i==text1.getText().length())
{
replacesetflag=true;
replacecode=new String(text1.getText());
subwin.setVisible(false);
new Warning("提示","设置成功");
}
else
new Warning("警告","必须输入互异字母单词");
}
}
catch(Exception E)
{
new Warning("提示","设置替换单词异常");
}
}
if(e.getSource()==button8)
{
int i,j;
char temp2[]=text1.getText().toCharArray();
try{
if(text1.getText().length()==0)
new Warning("警告","必须输入");
else
{
for(i=0;i<text1.getText().length();i++)
{
for(j=0;j<text1.getText().length();j++)
if((temp2[i]==temp2[j])&&i!=j)
break;
if(j!=text1.getText().length())
break;
}
if(i==text1.getText().length())
{
replaceopenflag=true;
replacecode=new String(text1.getText());
subwin.setVisible(false);
new Warning("提示","设置成功");
}
else
new Warning("警告","必须输入互异字母单词");
}
}
catch(Exception E)
{
new Warning("提示","设置替换单词异常");
}
}
if(e.getSource()==button9)
{
dessetflag=true;
subwin.setVisible(false);
new Warning("获取DES密钥","密钥获取中....");
}
}
public static void main(String[] args)
{
new Code();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -