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

📄 example.java

📁 java rc4 加密 rc4加密算法的一个实现
💻 JAVA
字号:
import java.security.InvalidKeyException;/** * @author reikon (Thomas Dixon) * This file is released into public domain. (no license) */public class Example {    private static final char[] HEX_DIGITS = {    '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};    	/**	 * @param args	 */	public static void main(String[] args) {        // Key we'll use to encrypt        byte[] testKey1 = {            (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67,             (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef        };                // Data we'll encrypt        byte[] testIn1 = {            (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67,             (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef        };                RC4 rc4 = new RC4();                try {            rc4.engineInit(testKey1);        } catch (InvalidKeyException ike) {            // handle errors with the key here            System.err.println(ike);        }                // arguments are (byte[] in data, int offset)        String result = toString(rc4.engineCrypt(testIn1,0));                // print result which is a hex string        System.out.println(result);                // For this exmaple, which is a test vector:        //        // Key   : 0123456789abcdef        // Input : 0123456789abcdef        // Output: 75b7878099e0c596        	} // main    private static String toString(byte[] ba) {        return toString(ba, 0, ba.length);    }    private static String toString(byte[] ba, int o00set, int length) {        char[] buf = new char[length * 2];        for (int i = 0, j = 0, k; i < length; i++) {            k = ba[o00set++];            buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];            buf[j++] = HEX_DIGITS[ k        & 0x0F];        }        return new String(buf);    }    }

⌨️ 快捷键说明

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