⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 DES算法全称为Data Encryption Standard,即数据加密算法,DES算法把64位的明文输入块变为64位的密文输出块,它所使用的密钥也是64位。RSA的安全性依赖于大数分解。公钥和私
💻 JAVA
字号:
package org.encryption.rsa;

import java.math.BigInteger;
import java.util.Random;

public class Test {
	public static void main(String[] args) {
		// BigInteger p = BigInteger.valueOf(101);
		// BigInteger q = BigInteger.valueOf(53);
		// BigInteger t =
		// p.subtract(BigInteger.valueOf(1L)).multiply(q.subtract(BigInteger.valueOf(1L)));
		// BigInteger e = BigInteger.valueOf(7L);
		// System.out.println(p.multiply(q).toString().length());
		// BigInteger d = e.modInverse(t);
		// System.out.println(d.toString());
//		System.out.println(XmodPow(new BigInteger("3260"),
//				BigInteger.valueOf(743L), BigInteger.valueOf(5353L)).toString());
//		BigInteger bb = new BigInteger("3260").pow(743);
//		System.out.println(bb.mod(BigInteger.valueOf(5353L)).toString());

		 System.out.println();
		 System.out.println("待加密的数字:"+"666666661234567890111111111111111111111111111111111111111111111222222222222");
		 RSAAlgorithm rsa = new RSAAlgorithm();
		 long t1=System.currentTimeMillis();
		 BigInteger bigInt =rsa.encrypt(new BigInteger("666666661234567890111111111111111111111111111111111111111111111222222222222"), true);
		 long t2 =System.currentTimeMillis();
		 System.out.println("-----------time:"+(t2-t1));
		 System.out.println("加密后:"+bigInt.toString());
		 System.out.println("解密后:"+rsa.decrypt(bigInt, false));
		 long t3 = System.currentTimeMillis();
		 System.out.println("-----------time:"+(t3-t2));
	}

	// private static BigInteger modPow(BigInteger a, BigInteger b, BigInteger
	// c) {
	// if (b.compareTo(BigInteger.ONE) == 0)
	// return a.mod(c);
	// BigInteger index = BigInteger.ONE;
	// BigInteger result = a.mod(c);
	// BigInteger temp = BigInteger.ONE;
	// while (index.compareTo(b) == -1) {
	// temp = result;
	// result = result.multiply(result).mod(c);
	// index = index.add(index);
	// }
	// if(index.compareTo(b) ==1)
	// result =
	// temp.multiply(modPow(a,b.subtract(index.divide(BigInteger.valueOf(2))),c)).mod(c);
	// return result;
	// }
	//
	// private static boolean isCompsite(BigInteger bigInt) {
	// if (bigInt.byteValue() % 2 == 0)
	// return true;
	// return false;
	// }

//	private static BigInteger XmodPow(BigInteger a, BigInteger b, BigInteger c) {
//
//		String bBinaryString = ToBinaryString(b.toByteArray());
//		BigInteger finalResult = BigInteger.ONE;
//		BigInteger tempResult = BigInteger.ONE;
//		for (int i = bBinaryString.length() - 1; i >= 0; i--) {
//			if (i == (bBinaryString.length() - 1))
//				tempResult= a.mod(c);
//			else
//				tempResult = tempResult.multiply(tempResult).mod(c);
//			if (bBinaryString.charAt(i) == '1') {
//				finalResult = finalResult.multiply(tempResult).mod(c);
//			}
//		}
//		return finalResult;
//	}
//
//	// 字节数组转化为字符串
//	private static String ToBinaryString(byte[] binary) {
//		StringBuffer strBuf = new StringBuffer();
//		String intStr;
//		for (int i = 0; i < binary.length; i++) {
//			intStr = Integer.toBinaryString(binary[i]);
//			if (intStr.length() == 8)
//				strBuf.append(intStr);
//			else if (intStr.length() > 8) {
//				strBuf.append(intStr.substring(intStr.length() - 8, intStr
//						.length()));
//			} else {
//				char[] padding = new char[8 - intStr.length()];
//				for (int j = 0; j < padding.length; j++)
//					padding[j] = '0';
//				strBuf.append(padding);
//				strBuf.append(intStr);
//			}
//		}
//		return strBuf.toString();
//	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -