// Path: src/main/net/sourceforge/jtds/util/DESEngine.java
// public class DESEngine
// {
//     protected static final int  BLOCK_SIZE = 8;
//     private Cipher cf;
// 
//     /**
//      * standard constructor.
//      */
//     public DESEngine() {
//         // nothing
//     }
// 
//     /**
//      * mdb: convenient constructor
//      */
//     public DESEngine( boolean encrypting, byte[] key ) {
//         init(encrypting, key);
//     }
// 
//     /**
//      * initialise a DES cipher.
//      *
//      * @param encrypting whether or not we are for encryption.
//      * @param key the parameters required to set up the cipher.
//      * @exception IllegalArgumentException if the params argument is
//      * inappropriate.
//      */
//     public void init(boolean encrypting, byte[] key) {
//         try {
//             KeySpec ks;
//             SecretKeyFactory kf;
//             SecretKey ky;
// 
//             ks = new DESKeySpec(key);
//             kf = SecretKeyFactory.getInstance("DES");
//             ky = kf.generateSecret(ks);
//             cf = Cipher.getInstance("DES/ECB/NoPadding");
//             cf.init(
//                     (encrypting ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE), 
//                     ky);
//         } catch (GeneralSecurityException e) {
//             throw new RuntimeException("Error initializing DESEngine", e);
//         }
//     }
// 
//     public String getAlgorithmName() {
//         return "DES";
//     }
// 
//     public int getBlockSize() {
//         return BLOCK_SIZE;
//     }
// 
//     public int processBlock(byte[] in, int inOff, byte[] out, int outOff) {
//         // rsc: keep the error behaviour as it was with the previous non-JDK implementation:
//         if (cf==null)
//         {
//             throw new IllegalStateException("DES engine not initialised");
//         }
// 
//         if ((inOff + BLOCK_SIZE) > in.length)
//         {
//             //mdb: used to be DataLengthException
//             throw new IllegalArgumentException("input buffer too short");
//         }
// 
//         if ((outOff + BLOCK_SIZE) > out.length)
//         {
//             //mdb: used to be DataLengthException
//             throw new IllegalArgumentException("output buffer too short");
//         }
// 
//         try {
//             int len = cf.doFinal(in, inOff, 8, out, outOff);
//             return len;
//         } catch (GeneralSecurityException e) {
//             throw new RuntimeException("Error processing data block in DESEngine", e);
//         }
//     }
// 
//     public void reset() {
//         // nothing
//     }
// 
// }


import junit.framework.TestCase;
import net.sourceforge.jtds.util.DESEngine;

                0x04, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 
                0x05, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 
                };
        byte [] dataKey = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
        byte [] dataExp = {
                (byte)0x77, (byte)0xa7, (byte)0xd6, (byte)0xbc, (byte)0xf5, (byte)0x79, (byte)0x62, (byte)0xb9, 
                (byte)0x77, (byte)0xa7, (byte)0xd6, (byte)0xbc, (byte)0xf5, (byte)0x79, (byte)0x62, (byte)0xb9, 
                (byte)0x77, (byte)0xa7, (byte)0xd6, (byte)0xbc, (byte)0xf5, (byte)0x79, (byte)0x62, (byte)0xb9, 
                (byte)0x77, (byte)0xa7, (byte)0xd6, (byte)0xbc, (byte)0xf5, (byte)0x79, (byte)0x62, (byte)0xb9, 

                (byte)0xca, (byte)0x48, (byte)0x26, (byte)0x21, (byte)0x75, (byte)0x95, (byte)0xee, (byte)0x3b, 
                (byte)0xcc, (byte)0x1a, (byte)0x27, (byte)0x1c, (byte)0xcd, (byte)0x29, (byte)0xfe, (byte)0x26, 
                (byte)0x0d, (byte)0x40, (byte)0x98, (byte)0x42, (byte)0xdd, (byte)0xa5, (byte)0xf8, (byte)0xbc, 
                (byte)0x7d, (byte)0x76, (byte)0x12, (byte)0x5b, (byte)0x63, (byte)0x00, (byte)0x5f, (byte)0x88, 
                };
        byte [] dataEnc = new byte[dataInp.length];
        byte [] dataDec = new byte[dataInp.length];
        // test encryption:
        {
            DESEngine desEngine = new DESEngine(true, dataKey);
            for (int i=0; i<dataInp.length; i += 8) {
                desEngine.processBlock(dataInp, i, dataEnc, i);
            }
            String strAct = Helper.dumpCodeBytes(dataEnc);
            String strExp = Helper.dumpCodeBytes(dataExp);
            assertEquals("encryption failed", strExp, strAct);
        }

        // test decryption:
        {

// Path: src/main/net/sourceforge/jtds/util/DESEngine.java
// public class DESEngine
// {
//     protected static final int  BLOCK_SIZE = 8;
//     private Cipher cf;
// 
//     /**
//      * standard constructor.
//      */
//     public DESEngine() {
//         // nothing
//     }
// 
//     /**
//      * mdb: convenient constructor
//      */
//     public DESEngine( boolean encrypting, byte[] key ) {
//         init(encrypting, key);
//     }
// 
//     /**
//      * initialise a DES cipher.
//      *
//      * @param encrypting whether or not we are for encryption.
//      * @param key the parameters required to set up the cipher.
//      * @exception IllegalArgumentException if the params argument is
//      * inappropriate.
//      */
//     public void init(boolean encrypting, byte[] key) {
//         try {
//             KeySpec ks;
//             SecretKeyFactory kf;
//             SecretKey ky;
// 
//             ks = new DESKeySpec(key);
//             kf = SecretKeyFactory.getInstance("DES");
//             ky = kf.generateSecret(ks);
//             cf = Cipher.getInstance("DES/ECB/NoPadding");
//             cf.init(
//                     (encrypting ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE), 
//                     ky);
//         } catch (GeneralSecurityException e) {
//             throw new RuntimeException("Error initializing DESEngine", e);
//         }
//     }
// 
//     public String getAlgorithmName() {
//         return "DES";
//     }
// 
//     public int getBlockSize() {
//         return BLOCK_SIZE;
//     }
// 
//     public int processBlock(byte[] in, int inOff, byte[] out, int outOff) {
//         // rsc: keep the error behaviour as it was with the previous non-JDK implementation:
//         if (cf==null)
//         {
//             throw new IllegalStateException("DES engine not initialised");
//         }
// 
//         if ((inOff + BLOCK_SIZE) > in.length)
//         {
//             //mdb: used to be DataLengthException
//             throw new IllegalArgumentException("input buffer too short");
//         }
// 
//         if ((outOff + BLOCK_SIZE) > out.length)
//         {
//             //mdb: used to be DataLengthException
//             throw new IllegalArgumentException("output buffer too short");
//         }
// 
//         try {
//             int len = cf.doFinal(in, inOff, 8, out, outOff);
//             return len;
//         } catch (GeneralSecurityException e) {
//             throw new RuntimeException("Error processing data block in DESEngine", e);
//         }
//     }
// 
//     public void reset() {
//         // nothing
//     }
// 
// }


// Path: src/test/net/sourceforge/jtds/jdbc/DESEngineTest.java
import junit.framework.TestCase;
import net.sourceforge.jtds.util.DESEngine;

                0x04, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 
                0x05, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 
                };
        byte [] dataKey = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
        byte [] dataExp = {
                (byte)0x77, (byte)0xa7, (byte)0xd6, (byte)0xbc, (byte)0xf5, (byte)0x79, (byte)0x62, (byte)0xb9, 
                (byte)0x77, (byte)0xa7, (byte)0xd6, (byte)0xbc, (byte)0xf5, (byte)0x79, (byte)0x62, (byte)0xb9, 
                (byte)0x77, (byte)0xa7, (byte)0xd6, (byte)0xbc, (byte)0xf5, (byte)0x79, (byte)0x62, (byte)0xb9, 
                (byte)0x77, (byte)0xa7, (byte)0xd6, (byte)0xbc, (byte)0xf5, (byte)0x79, (byte)0x62, (byte)0xb9, 

                (byte)0xca, (byte)0x48, (byte)0x26, (byte)0x21, (byte)0x75, (byte)0x95, (byte)0xee, (byte)0x3b, 
                (byte)0xcc, (byte)0x1a, (byte)0x27, (byte)0x1c, (byte)0xcd, (byte)0x29, (byte)0xfe, (byte)0x26, 
                (byte)0x0d, (byte)0x40, (byte)0x98, (byte)0x42, (byte)0xdd, (byte)0xa5, (byte)0xf8, (byte)0xbc, 
                (byte)0x7d, (byte)0x76, (byte)0x12, (byte)0x5b, (byte)0x63, (byte)0x00, (byte)0x5f, (byte)0x88, 
                };
        byte [] dataEnc = new byte[dataInp.length];
        byte [] dataDec = new byte[dataInp.length];
        // test encryption:
        {
            DESEngine desEngine = new DESEngine(true, dataKey);
            for (int i=0; i<dataInp.length; i += 8) {
                desEngine.processBlock(dataInp, i, dataEnc, i);
            }
            String strAct = Helper.dumpCodeBytes(dataEnc);
            String strExp = Helper.dumpCodeBytes(dataExp);
            assertEquals("encryption failed", strExp, strAct);
        }

        // test decryption:
        {

            DESEngine desEngine = new DESEngine(false, dataKey);
