这是des报告的代码,一共2个java文件,复制粘贴就可以啦~
//BitsArray.java
package my_src;
import java.io.*;
import java.util.Random;
public class BitsArray {
// public BitsArray(String bits) {
// super();
// this.bits = new byte[64];
// }
// public static String RandomBits() {
// String s="";
// Random random=new Random();
// int c=random.nextInt();
// int d=random.nextInt();
// s+=Integer.toBinaryString(c)+Integer.toBinaryString(d);
// int total=64-s.length();
// for(int i=0;i'0'?'0':'1';
}
String s="";
for(int i=0;i
//des_statics.java
package my_src;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import static my_src.BitsArray.*;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class des_statistic {
public static void main(String[] args) {
// TODO Auto-generated method stub
Cipher des = null;
// 存放 密钥
byte[] des_key = new byte[8];
// 存放 明文
byte[] des_input = new byte[8];
// 存放 加密后的输出
byte[] des_output = null;
for(int i=0; i < 8; i++)
{
des_key[i] = 0x11;
des_input[i] = 0x11;
}
SecretKey secretKey = new SecretKeySpec(des_key, "DES");
// 创建des 密码算法对象,指定电码本模式和无填充方式
try {
des = Cipher.getInstance("DES/ECB/NoPadding");
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 初始化 des 算法
try {
des.init(Cipher.ENCRYPT_MODE, secretKey);
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 加密
try {
des_output = des.doFinal(des_input);
} catch (IllegalBlockSizeException | BadPaddingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
changeInput(des_key, des_input, des_output);
changeCipher(des_key, des_input, des_output);
}
public static void changeCipher(byte[] des_key,byte[] des_input,byte[] des_output){
Cipher des=null;
SecretKey secretKey=null;
int randtimes=10;
int deffOnOut=0;
byte[] randDes_output=null;
String des_keyString=bitsToString(des_key);
String des_outputString=bitsToString(des_output);
String randDes_keyString="";
String randDes_outputString="";
byte[] randDes_key=null;
// 创建des 密码算法对象,指定电码本模式和无填充方式
try {
des = Cipher.getInstance("DES/ECB/NoPadding");
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
e.printStackTrace();
}
for(int i=1;i<=64;i++) {
for(int j=0;j 


