?? hushrandom.java
字號:
/* * File: HushRandom.java * * Extends the Random class, for better random numbers. * * version 1.02 v1a * Copyright 1998, 1999 by Hush Communications Corporation, BWI */package hushcode;import java.util.Random;import hushcode.HushSHA1;final class HushRandom extends Random{ byte[] randBytes = new byte[128]; public HushRandom(byte[] seed) { /* seed should be strength/8 bytes long */ enqueueBytes(seed); } public void nextBytes(byte[] bytes) { //System.out.println(bytes.length + " bytes requested); int bytesGenerated = 0; while (bytes.length - bytesGenerated > 10) { byte[] hashedBytes = new HushSHA1().SHA1Hash(randBytes); //System.out.println("Hash: "+Conversions.bytesToHexString(hashedBytes)); System.arraycopy(hashedBytes,0,bytes,bytesGenerated,10); enqueueBytes(hashedBytes,10,10); bytesGenerated = bytesGenerated + 10; } byte[] hashedBytes = new HushSHA1().SHA1Hash(randBytes); //System.out.println("Hash: "+Conversions.bytesToHexString(hashedBytes)); System.arraycopy(hashedBytes,0,bytes,bytesGenerated,bytes.length-bytesGenerated); enqueueBytes(hashedBytes,bytes.length-bytesGenerated,20-(bytes.length-bytesGenerated)); //System.out.println("Returned value: "+Conversions.bytesToHexString(bytes)); } public void enqueueBytes(byte[] passedBytes, int offset, int length) { byte[] bytes = new byte[length]; System.arraycopy(passedBytes,offset,bytes,0,length); enqueueBytes(bytes); } public void enqueueBytes(byte[] bytes) { //System.out.println("Originally: "+Conversions.bytesToHexString(randBytes)); //System.out.println("Enqueueing: "+Conversions.bytesToHexString(bytes)); for (int n=127-bytes.length; n>=0; n--) { randBytes[n+bytes.length]=randBytes[n]; } System.arraycopy(bytes,0,randBytes,0,bytes.length); //System.out.println("Now: "+Conversions.bytesToHexString(randBytes)); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -