📄 encode.jad
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2009-1-11 22:07:18
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: encode.java
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class encode
{
class myMap
{
public char ch;
public int rate;
final encode this$0;
public myMap(char c1, int i)
{
this$0 = encode.this;
super();
ch = c1;
rate = i;
}
}
public encode()
{
}
public void show()
{
al = new JLabel("parameter a=");
bl = new JLabel("parameter b=");
atxt = new JTextField(2);
btxt = new JTextField(2);
pexplain = new JLabel("Input the plain text:");
cexplain = new JLabel("After encoded:");
plainContainer = new JTextField(50);
codeContainer = new JTextField(50);
submit = new JButton("enCode");
decode = new JButton("deCode");
statisticExplain1 = new JLabel("plain Statistic:");
statisticExplain2 = new JLabel("code Statistic:");
statisticContainer1 = new JTextField(50);
statisticContainer2 = new JTextField(50);
cau = new JLabel(" message ");
caution = new JTextField(50);
p = new ArrayList(26);
c = new ArrayList(26);
for(int i = 0; i < 26; i++)
{
p.add(new myMap((char)(97 + i), 0));
c.add(new myMap((char)(97 + i), 0));
}
plainText = null;
codeText = null;
a = -1;
b = -1;
lineSep = ";";
mframe = new JFrame("CodeHelper");
mframe.setSize(800, 200);
mframe.setVisible(true);
mc = mframe.getContentPane();
j1 = new JPanel();
j2 = new JPanel();
j3 = new JPanel();
j4 = new JPanel();
j5 = new JPanel();
j6 = new JPanel();
j7 = new JPanel();
j1.setLayout(new BoxLayout(j1, 1));
j1.add(al);
j1.add(bl);
mc.add(j1);
j2.setLayout(new BoxLayout(j2, 1));
j2.add(atxt);
j2.add(btxt);
mc.add(j2);
j3.setLayout(new BoxLayout(j3, 1));
j3.add(pexplain);
j3.add(cexplain);
mc.add(j3);
j4.setLayout(new BoxLayout(j4, 1));
j4.add(plainContainer);
j4.add(codeContainer);
mc.add(j4);
j5.setLayout(new BoxLayout(j5, 1));
j5.add(statisticExplain1);
j5.add(statisticExplain2);
j5.add(cau);
mc.add(j5);
j6.setLayout(new BoxLayout(j6, 1));
j6.add(statisticContainer1);
j6.add(statisticContainer2);
j6.add(caution);
mc.add(j6);
j7.setLayout(new BoxLayout(j7, 1));
j7.add(submit);
j7.add(decode);
mc.add(j7);
caution.setEditable(false);
mframe.setLayout(new FlowLayout());
}
public void addlistener()
{
mframe.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowevent)
{
System.exit(0);
}
final encode this$0;
{
this$0 = encode.this;
super();
}
});
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent)
{
try
{
a = Integer.parseInt(atxt.getText());
a = (a % 26 + 26) % 26;
b = Integer.parseInt(btxt.getText());
b = (b % 26 + 26) % 26;
}
catch(Exception exception)
{
caution.setText((new StringBuilder()).append(atxt.getText()).append(" or ").append(btxt.getText()).append("is not number").toString());
a = -1;
b = -1;
atxt.setText("");
btxt.setText("");
plainContainer.setText("");
codeContainer.setText("");
statisticContainer1.setText("");
statisticContainer2.setText("");
return;
}
if(gcd(a, 26) != 1)
{
caution.setText((new StringBuilder()).append(a).append(" is not a illegal number!").toString());
atxt.setText("");
a = -1;
plainContainer.setText("");
codeContainer.setText("");
statisticContainer1.setText("");
statisticContainer2.setText("");
return;
}
plainText = plainContainer.getText();
if(plainText != "" && plainText != null && a >= 0 && b >= 0)
{
codeText = transform(a, b, plainText.trim());
codeContainer.setText(codeText);
StringBuffer stringbuffer = new StringBuffer();
for(int i = 0; i < 26; i++)
{
if(((myMap)p.get(i)).rate != 0)
stringbuffer.append((new StringBuilder()).append(" ").append(((myMap)p.get(i)).ch).append(" : ").append((double)((myMap)p.get(i)).rate / (double)plainText.length()).append(lineSep).toString());
((myMap)p.get(i)).rate = 0;
}
statisticContainer1.setText(stringbuffer.toString());
stringbuffer = new StringBuffer();
for(int j = 0; j < 26; j++)
{
if(((myMap)c.get(j)).rate != 0)
stringbuffer.append((new StringBuilder()).append(" ").append(((myMap)c.get(j)).ch).append(" : ").append((double)((myMap)c.get(j)).rate / (double)plainText.length()).append(lineSep).toString());
((myMap)c.get(j)).rate = 0;
}
statisticContainer2.setText(stringbuffer.toString());
caution.setText("work well!");
} else
{
caution.setText("error in prameter a or b or plaintext!");
atxt.setText("");
btxt.setText("");
}
}
final encode this$0;
{
this$0 = encode.this;
super();
}
});
decode.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent)
{
try
{
a = Integer.parseInt(atxt.getText());
a = (a % 26 + 26) % 26;
b = Integer.parseInt(btxt.getText());
b = (b % 26 + 26) % 26;
}
catch(Exception exception)
{
caution.setText((new StringBuilder()).append(atxt.getText()).append(" or ").append(btxt.getText()).append(" is not number").toString());
a = -1;
b = -1;
atxt.setText("");
btxt.setText("");
plainContainer.setText("");
codeContainer.setText("");
statisticContainer1.setText("");
statisticContainer2.setText("");
return;
}
if(gcd(a, 26) != 1)
{
caution.setText((new StringBuilder()).append(a).append(" is a illegal number!").toString());
atxt.setText("");
a = -1;
plainContainer.setText("");
codeContainer.setText("");
statisticContainer1.setText("");
statisticContainer2.setText("");
return;
}
codeText = codeContainer.getText();
if(codeText != "" && codeText != null && a >= 0 && b >= 0)
{
plainText = atransform(a, b, codeText.trim());
plainContainer.setText(plainText);
StringBuffer stringbuffer = new StringBuffer();
for(int i = 0; i < 26; i++)
{
if(((myMap)p.get(i)).rate != 0)
stringbuffer.append((new StringBuilder()).append(" ").append(((myMap)p.get(i)).ch).append(" : ").append((double)((myMap)p.get(i)).rate / (double)plainText.length()).append(lineSep).toString());
((myMap)p.get(i)).rate = 0;
}
statisticContainer1.setText(stringbuffer.toString());
stringbuffer = new StringBuffer();
for(int j = 0; j < 26; j++)
{
if(((myMap)c.get(j)).rate != 0)
stringbuffer.append((new StringBuilder()).append(" ").append(((myMap)c.get(j)).ch).append(" : ").append((double)((myMap)c.get(j)).rate / (double)plainText.length()).append(lineSep).toString());
((myMap)c.get(j)).rate = 0;
}
statisticContainer2.setText(stringbuffer.toString());
caution.setText("work well!");
} else
{
caution.setText("error in prameter a or b or plaintext!");
atxt.setText("");
btxt.setText("");
}
}
final encode this$0;
{
this$0 = encode.this;
super();
}
});
}
public static void main(String args[])
{
encode encode1 = new encode();
encode1.show();
encode1.addlistener();
}
public String transform(int i, int j, String s)
{
int k = s.length();
char ac[] = s.toLowerCase().toCharArray();
for(int l = 0; l < k; l++)
if(ac[l] >= 'a' && ac[l] <= 'z')
{
((myMap)p.get(ac[l] - 97)).rate++;
ac[l] = (char)(((ac[l] - 97) * i + j) % 26 + 97);
((myMap)c.get(ac[l] - 97)).rate++;
}
return new String(ac);
}
public int gcd(int i, int j)
{
if(i >= 0 && j >= 0)
{
for(int k = i % j; k != 0; k = i % j)
{
i = j;
j = k;
}
return j;
} else
{
return -1;
}
}
public String atransform(int i, int j, String s)
{
int k = s.length();
char ac[] = s.toLowerCase().toCharArray();
for(int l = 0; l < k; l++)
if(ac[l] >= 'a' && ac[l] <= 'z')
{
((myMap)c.get(ac[l] - 97)).rate++;
ac[l] = (char)(((((ac[l] - 97 - j) % 26 + 26) % 26) * rev(i, 26)) % 26 + 97);
((myMap)p.get(ac[l] - 97)).rate++;
}
return new String(ac);
}
public int rev(int i, int j)
{
if(gcd(i, j) == 1)
{
int k;
for(k = 1; (j * k + 1) % i != 0; k++);
return (j * k + 1) / i;
} else
{
return -1;
}
}
private String lineSep;
private int a;
private int b;
private String plainText;
private String codeText;
private JFrame mframe;
private Container mc;
private JLabel al;
private JLabel bl;
private JLabel pexplain;
private JLabel cexplain;
private JLabel statisticExplain1;
private JLabel statisticExplain2;
private JTextField atxt;
private JTextField btxt;
private JTextField plainContainer;
private JTextField codeContainer;
private JTextField statisticContainer1;
private JTextField statisticContainer2;
JButton submit;
JButton decode;
ArrayList p;
ArrayList c;
JTextField caution;
JLabel cau;
JPanel j1;
JPanel j2;
JPanel j3;
JPanel j4;
JPanel j5;
JPanel j6;
JPanel j7;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -