protected void engineTest() throws Exception { setExpectedPasses(7); String[][] data = { // data, md // ...................... {"", "8350E5A3E24C153DF2275C9F80692773"}, // A.5 1 {"a", "32EC01EC4A6DAC72C0AB96FB34C0B5D1"}, // A.5 2 {"abc", "DA853B0D3F88D99B30283A69E6DED6BB"}, // A.5 3 {"message digest", "AB4F496BFB2A530B219FF33031FE06B0"}, // A.5 4 {"abcdefghijklmnopqrstuvwxyz", "4E8DDFF3650292AB5A4108C3AA47940B"}, // A.5 5 { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "DA33DEF2A42DF13975352846C30338CD" }, // A.5 6 { "12345678901234567890123456789012345678901234567890123456789012345678901234567890", "D5976F79D83D3A0DC9806C3C66F3EFD8" } // A.5 7 }; MessageDigest alg = MessageDigest.getInstance("MD2", "Cryptix"); for (int i = 0; i < data.length; i++) { String a = Hex.toString(alg.digest(data[i][0].getBytes())); out.println(" test vector: " + data[i][0]); out.println(" computed md: " + a); out.println(" certified md: " + data[i][1]); passIf(a.equals(data[i][1]), "MD2 #" + (i + 1)); } }
private void test1() throws Exception { byte[] ect, dct; String a, b; int i; for (i = 0; i < testData1.length; i++) { Cipher alg = Cipher.getInstance("SPEED", "Cryptix"); ((Parameterized) alg).setParameter("rounds", new Integer(testData1[i][0])); ((Parameterized) alg).setParameter("blockSize", new Integer(testData1[i][2].length() / 2)); RawSecretKey key = new RawSecretKey("SPEED", Hex.fromString(testData1[i][1])); alg.initEncrypt(key); ect = alg.crypt(Hex.fromString(testData1[i][2])); a = Hex.toString(ect); alg.initDecrypt(key); dct = alg.crypt(ect); b = Hex.toString(dct); out.println(" plain: " + testData1[i][2]); out.println(" cipher: " + a); out.println(" cert: " + testData1[i][3]); passIf(a.equals(testData1[i][3]), " *** SPEED encrypt"); out.println(" cipher: " + Hex.toString(ect)); out.println(" plain: " + b); out.println(" cert: " + testData1[i][2]); passIf(b.equals(testData1[i][2]), " *** SPEED decrypt"); // // print reversed data for replacing/comparing in the data above // out.println("\n \"" + // Hex.toString(Hex.fromReversedString(testData1[i][1])) + "\""); // out.println(" \"" + // Hex.toString(Hex.fromReversedString(testData1[i][2])) + "\""); // out.println(" \"" + // Hex.toString(Hex.fromReversedString(testData1[i][3])) + "\"\n"); } }
private static void test( PrintWriter out, int rounds, String keyStr, String plainStr, String cipherStr) throws Exception { // Note that the paper uses certification data that is indexed // from RIGHT to LEFT, i.e., 7, 6, 5, 4, 3, 2, 1, 0. byte keyBytes[] = Hex.fromReversedString(keyStr); byte plain[] = Hex.fromReversedString(plainStr); byte cipher[] = Hex.fromReversedString(cipherStr); SPEED speed = new SPEED(); speed.setBlockSize(plain.length); speed.setRounds(rounds); Key key = new RawSecretKey("SPEED", keyBytes); speed.initEncrypt(key); byte encP[] = speed.crypt(plain); String a, b; out.println(" key:" + Hex.toString(keyBytes)); out.println(" plain:" + Hex.toString(plain)); out.println(" enc:" + (a = Hex.toString(encP))); b = Hex.toString(cipher); if (a.equals(b)) out.print("encryption good; "); else { out.println(" calc:" + b); out.println(" ********* SPEED ENCRYPTION FAILED ********* "); speed.dump(); } speed.initDecrypt(key); byte[] decC = speed.crypt(encP); a = Hex.toString(decC); b = Hex.toString(plain); if (a.equals(b)) out.println("decryption good"); else { out.println(); out.println(" enc:" + Hex.toString(encP)); out.println(" dec:" + a); out.println(" calc:" + b); out.println(" ********* SPEED DECRYPTION FAILED ********* "); speed.dump(); } }