广东工业大学 信息安全概论
- 网上搜索DES的源代码。
- 利用DES源代码实现下面功能:
① 统计DES算法在密钥固定情况,输入明文改变1位、2位,。。。64位时。输出密文位数改变情况。
② 统计DES算法在明文固定情况,输入密钥改变1位、2位,。。。64位时。输出密文位数改变情况。
- 注:为了具有客观性,①,②小题需要对多次进行统计,并计算其平均值。
package SymmetricEncryption;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
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;
public class DES
{
public static void main(String[] args)
{
byte[] des_key = new byte[8];
byte[] des_input = new byte[8];
System.out.println("The default plaintext is 1111111111111111");
System.out.println("The default key is 1111111111111111");
for (int i = 0; i < 8; i++)
{
des_key[i] = 0x11;
des_input[i] = 0x11;
}
byte[] des_output = encrypt(des_key, des_input);
System.out.println("The cipher text is " + byteArrayToHex(des_output));
System.out.println("------------------------------------------");
BitsArray key = new BitsArray(des_key);
BitsArray input = new BitsArray(des_input);
BitsArray output = new BitsArray(des_output);
System.out.print("Please enter which one you want to change (1.Plaintext 2.Key): ");
Scanner scan1 = new Scanner(System.in);
int select = scan1.nextInt();
if(select > 2 || select < 1)
{
System.out.println("Please enter the correct number!");
System.exit(0);
}
if(select == 1)
{
for(int bits = 1; bits <= 64; bits++)
{
int count = 0;
for(int j = 0; j < 10; j++)
{
HashSet