Cryptography Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.00
 This site Web DES Algorithm - Illustrated with Java Programs Part:   1  2  3  4  5  6  This chapter describes: A Java program to illustrate the DES key schedule Algorithm. A Java program to illustrate the DES cipher algorithm. DESSubkeysTest.java - DES Key Schedule Algorithm Illustration As an illustration to the DES key schedule algorithm described in the previous chapter, I wrote the following Java program, DESKSubkeysTest.java: ```/* DESSubkeysTest.java * Copyright (c) 2002 by Dr. Herong Yang */ class DESSubkeysTest { public static void main(String[] a) { try { byte[] theKey = getTestKey(); byte[][] subKeys = getSubkeys(theKey); boolean ok = validateSubkeys(subKeys); System.out.println("DES subkeys test result: "+ok); } catch (Exception e) { e.printStackTrace(); } } static final int[] PC1 = { 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 }; static final int[] PC2 = { 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 }; static final int[] SHIFTS = { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 }; private static byte[][] getSubkeys(byte[] theKey) throws Exception { printBytes(theKey,"Input key"); int activeKeySize = PC1.length; int numOfSubKeys = SHIFTS.length; byte[] activeKey = selectBits(theKey,PC1); printBytes(activeKey,"After permuted choice 1 - Active key"); int halfKeySize = activeKeySize/2; byte[] c = selectBits(activeKey,0,halfKeySize); byte[] d = selectBits(activeKey,halfKeySize,halfKeySize); byte[][] subKeys = new byte[numOfSubKeys][]; for (int k=0; k

Dr. Herong Yang, updated in 2007
Cryptography Tutorials - Herong's Tutorial Notes - DES Algorithm - Illustrated with Java Programs