package src;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Hashtable;
import java.util.Random;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
class Element{
int prefix;
int suffix;
public Element(int prefix, int suffix){
this.prefix = prefix;
this.suffix = suffix;
}
}
public class Tool {
static public Dimension buttonSize = new Dimension(100, 28);
static public Dimension buttonSize2 = new Dimension(130, 28);
static private int leftOver = 0;
static private boolean bitsLeftOver = false;
static public char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F' };
static public char base64[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '+', '/' };
static public String dec2hex(int data) {
int a, b, c, d;
if (data > 0xff) {
return null;
}
// a = (data >> 12) & 0x000f;
// b = (data >> 8) & 0x000f;
c = (data >> 4) & 0x000f;
d = data & 0x000f;
//return "" + hex[a] + hex[b] + hex[c] + hex[d];
return "" + hex[c] + hex[d];
}
// static public int hex2dec(char a, char b, char c, char d) {
// int ra, rb, rc, rd = 0;
// if ((a >= 'A') && (a <= 'F')) {
// ra = (int) (a - 'A' + 10);
// } else {
// ra = (int) (a - '0');
// }
// if ((b >= 'A') && (b <= 'F')) {
// rb = (int) (b - 'A' + 10);
// } else {
// rb = (int) (b - '0');
// }
// if ((c >= 'A') && (c <= 'F')) {
// rc = (int) (c - 'A' + 10);
// } else {
// rc = (int) (c - '0');
// }
// if ((d >= 'A') && (d <= 'F')) {
// rd = (int) (d - 'A' + 10);
// } else {
// rd = (int) (d - '0');
// }
// return ((ra << 12) | (rb << 8) | (rc << 4) | rd);
// }
// static public String dec2hex(byte data) {
// byte a, b;
// a = (byte) (data >> 4 & 0x0f);
// b = (byte) (data & 0x0f);
// return "" + hex[a] + hex[b];
// }
static public int hex2dec(char a, char b) {
int ra, rb;
if ((a >= 'A') && (a <= 'F')) {
ra = (byte) (a - 'A' + 10);
} else {
ra = (byte) (a - '0');
}
if ((b >= 'A') && (b <= 'F')) {
rb = (byte) (b - 'A' + 10);
} else {
rb = (byte) (b - '0');
}
return ((ra << 4) | rb);
}
static public int indexOfBase(char ch) {
if ((ch >= 'A') && (ch <= 'Z')) {
return (int) (ch - 'A');
} else if ((ch >= 'a') && (ch <= 'z')) {
return (int) (ch - 'a' + 26);
} else if ((ch >= '0') && (ch <= '9')) {
return (int) (ch - '0' + 26 + 26);
} else if (ch == '+') {
return 62;
} else if (ch == '/') {
return 63;
}
return 0;
}
static public void add2bag(JPanel pane, Component com, int gx, int gy,
int gw, int gh, int pos, int fill) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = gbc.weighty = 100;
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.anchor = pos;
gbc.fill = fill;
pane.add(com, gbc);
}
static public File selectFile(Component parent, String ext, String des,
boolean isOpen) {
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File("."));
fc.setFileFilter(new KeyFilter(ext, des));
int re;
if (isOpen) {
re = fc.showOpenDialog(parent);
} else {
re = fc.showSaveDialog(parent);
}
if (re == JFileChooser.APPROVE_OPTION) {
return fc.getSelectedFile();
} else {
return null;
}
}
static public String readFile(Component parent, File file) {
if (file == null) {
return null;
}
try {
FileInputStream in = new FileInputStream(file.getPath());
byte[] data = new byte[in.available()];
in.read(data);
in.close();
return new String(data);
} catch (Exception e) {
JOptionPane.showMessageDialog(parent, "文件读取失败");
return null;
}
}
static public void writeFile(Component parent, File file, String str) {
if (file == null) {
return;
}
try {
FileOutputStream out = new FileOutputStream(file.getPath());
byte[] data = str.getBytes();
out.write(data);
out.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(parent, "文件写入失败");
}
}
static public BigInteger string2big(String data) {
String result = "";
for (int i = 0; i < data.length(); i++) {
byte bs = (byte) data.charAt(i);
if ((bs & 0x80) > 0)
result = result + "1";
else
result = result + "0";
if ((bs & 0x40) > 0)
result = result + "1";
else
result = result + "0";
if ((bs & 0x20) > 0)
result = result + "1";
else
result = result + "0";
if ((bs & 0x10) > 0)
result = result + "1";
else
result = result + "0";
if ((bs & 0x08) > 0)
result = result + "1";
else
result = result + "0";
if ((bs & 0x04) > 0)
result = result + "1";
else
result = result + "0";
if ((bs & 0x02) > 0)
result = result + "1";
else
result = result + "0";
if ((bs & 0x01) > 0)
result = result + "1";
else
result = result + "0";
}
return new BigInteger(result, 2);
}
static public String big2string(BigInteger data) {
String result = "";
byte[] bs = data.toByteArray();
result = new String(bs);
return result;
}
static public String string2hex(String data) {
String result = "";
String charset = "0123456789ABCDEF";
int i, t, j, k;
for (i = t = 0; i < data.length(); i++) {
t = (int) data.charAt(i);
j = (t & 0x0F);
k = (t & 0xF0) >> 4;
result += charset.charAt(k);
result += charset.charAt(j);
}
return result;
}
static public String hex2string(String data) {
String result = "";
int i, t, j, k;
char ch1, ch2;
for (i = 0; i < data.length() / 2; i++) {
ch1 = data.charAt(i + i);
ch2 = data.charAt(i + i + 1);
if ((ch1 >= '0') && (ch1 <= '9'))
j = (int)(ch1 - '0');
else
j = (int)(ch1 - 'A') + 10;
if ((ch2 >= '0') && (ch2 <= '9'))
k = (int)(ch2 - '0');
else
k = (int)(ch2 - 'A') + 10;
t = (j << 4) + k;
result += (char)t;
}
return result;
}
static public String string2base(String data) {
int remainder = data.length() % 3;
int i, t, j, k;
String st = data, result = "";
if (remainder == 2) {
st = st + (char) (0);
} else if (remainder == 1) {
st = st + (char) (0) + (char) (0);
}
for (i = t = 0; i < st.length() / 3; i++) {
t = (int) st.charAt(i * 3);
j = (int) st.charAt(i * 3 + 1);
k = (int) st.charAt(i * 3 + 2);
result += Tool.base64[(t >> 2) & 0x3f];
result += Tool.base64[((t & 0x03) << 4) | ((j & 0xf0) >> 4)];
result += Tool.base64[((j & 0x0f) << 2) | ((k & 0xc0) >> 6)];
result += Tool.base64[k & 0x3f];
}
if (remainder == 1) {
result = result.substring(0, result.length() - 2) + "==";
} else if (remainder == 2) {
result = result.substring(0, result.length() - 1) + "=";
}
return result;
}
static public String big2base(BigInteger data) {
String result = "";
String st = data.toString(2);
String temp;
while (st.length() % 24 > 0) {
st = "0" + st;
}
while (st.length() > 0) {
temp = "00" + st.substring(0,
没有合适的资源?快使用搜索试试~ 我知道了~
AES等算法的代码
共681个文件
class:437个
gif:103个
properties:53个
需积分: 0 19 下载量 129 浏览量
2008-11-11
00:08:29
上传
评论
收藏 3.05MB RAR 举报
温馨提示
各算法代码和相关信息
资源详情
资源评论
资源推荐
收起资源包目录
AES等算法的代码 (681个子文件)
GridCore.class 50KB
TreeCore.class 46KB
ListCore.class 35KB
TabsetView.class 26KB
GridView.class 25KB
FieldView.class 22KB
GridControl.class 22KB
TreeView.class 17KB
ListView.class 15KB
ResIndex.class 15KB
Res.class 15KB
ColorChooserPanel.class 15KB
Tool.class 15KB
HeaderView.class 14KB
ButtonDialog.class 14KB
ButtonBar.class 14KB
MaskableTextItemEditor.class 13KB
ButtonView.class 13KB
ListControl.class 12KB
MainFrame.class 11KB
ResTable.class 11KB
DataSetModel.class 10KB
GridControl_PopupSupport.class 10KB
BorderItemPainter.class 9KB
BeanPanel.class 9KB
CompositeItemPainter.class 9KB
PaneNode.class 9KB
PickListItemEditor.class 8KB
BasicMatrixContainer.class 8KB
PaneLayout.class 8KB
CheckboxPanel.class 8KB
ColumnView.class 8KB
PopupPickListItemEditor.class 8KB
TabsetPanel.class 8KB
TextFieldControl.class 8KB
TextAreaControl.class 8KB
GridControlBeanInfo.class 7KB
FontChooserPanel.class 7KB
FieldControl.class 7KB
CompositeItemEditor.class 7KB
NavigatorControl.class 7KB
ImageLoader.class 7KB
Res.class 7KB
ExceptionDialog.class 7KB
Res.class 6KB
LookupDialog.class 6KB
String2DArrayEditorPanel.class 6KB
ButtonControl.class 6KB
GridViewBeanInfo.class 6KB
TextItemPainter.class 6KB
ChoiceControl.class 6KB
ResIndex.class 6KB
CheckboxItemPainter.class 6KB
Operation.class 6KB
ChoiceView.class 6KB
TransparentImage.class 6KB
MatrixDataSetManager.class 6KB
TextAreaView.class 6KB
MultiColumnMatrixSelection.class 6KB
StringArrayEditorPanel.class 6KB
MultiRowMatrixSelection.class 6KB
String2DArrayEditor.class 6KB
SplitPanel.class 6KB
CheckboxControl.class 6KB
ListControlBeanInfo.class 6KB
Show.class 6KB
TreeControl.class 6KB
ImageControl.class 6KB
BasicVectorContainer.class 5KB
ResIndex.class 5KB
TreeControlBeanInfo.class 5KB
DSA$KeyPanel.class 5KB
MonitorPanel.class 5KB
StatusBar.class 5KB
CrossMatrixSelection.class 5KB
CustomItemEditor.class 5KB
ResTable.class 5KB
Message.class 5KB
GraphModelSearch.class 5KB
DSAKey$KeyPPanel.class 5KB
SelectableItemPainter.class 5KB
SingleMatrixSelection.class 5KB
TextFieldView.class 5KB
LSB_Method.class 5KB
ImageItemPainter.class 5KB
Filer.class 5KB
BasicMatrixSelection.class 5KB
BevelPanel.class 5KB
ListViewBeanInfo.class 5KB
ButtonBarBeanInfo.class 5KB
StringArrayEditor.class 5KB
DottedLine.class 5KB
StringEditor.class 5KB
LinkedTreeContainer.class 5KB
TypedViewManager.class 5KB
RSA$KeyPanel.class 5KB
VectorDataSetManager.class 5KB
XYLayout.class 5KB
LinkedTreeNode.class 5KB
DecoratedFrame.class 5KB
共 681 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
syh0e0e
- 粉丝: 0
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0