### Question:
DES extends SymmetricCipher { @Override public void encrypt_ctr(OpenSSLRSAPEM.INTEGER counter, byte[] key, ByteArrayInputStream is, ByteArrayOutputStream os) throws IOException { byte[] temp = new byte[DES.BLOCK_SIZE]; byte[] cipher = new byte[DES.BLOCK_SIZE]; while (is.available() > 0) { encrypt(extractBlock(counter.getBytes()), extractKey(key), cipher); int read = is.read(temp); for (int i = 0; i < read; i++) { os.write(temp[i] ^ cipher[i]); } } }  @Override void encrypt_ctr(OpenSSLRSAPEM.INTEGER counter, byte[] key, ByteArrayInputStream is, ByteArrayOutputStream os);  }### Answer:
@Test public void testRijndaelEncrypt() throws Exception { byte[] key = {59,31,-7,-54,10,38,-91,-31}; OpenSSLRSAPEM.INTEGER counter = OpenSSLRSAPEM.INTEGER.randomLong(); OpenSSLRSAPEM.INTEGER ccopy = new OpenSSLRSAPEM.INTEGER(counter); byte[] MSGBytes,CipherBytes, PTBytes; MSGBytes = MSG.getBytes(Charset.defaultCharset()); ByteArrayInputStream is = new ByteArrayInputStream(MSGBytes); ByteArrayOutputStream os = new ByteArrayOutputStream(MSGBytes.length); des.encrypt_ctr(counter, key, is, os); CipherBytes = os.toByteArray(); is = new ByteArrayInputStream(CipherBytes); os = new ByteArrayOutputStream(CipherBytes.length); des.encrypt_ctr(ccopy, key, is, os); PTBytes = os.toByteArray(); Assert.assertArrayEquals(MSGBytes, PTBytes); }
@Test public void testDESEncryptDecrypt() throws Exception { byte[] key = {59,31,-7,-54,10,38,-91,-31}; OpenSSLRSAPEM.INTEGER counter = OpenSSLRSAPEM.INTEGER.randomLong(); OpenSSLRSAPEM.INTEGER ccopy = counter.duplicate(); byte[] MSGBytes,CipherBytes, PTBytes; MSGBytes = MSG.getBytes(Charset.defaultCharset()); ByteArrayInputStream is = new ByteArrayInputStream(MSGBytes); ByteArrayOutputStream os = new ByteArrayOutputStream(MSGBytes.length); des.encrypt_ctr(counter, key, is, os); CipherBytes = os.toByteArray(); is = new ByteArrayInputStream(CipherBytes); os = new ByteArrayOutputStream(CipherBytes.length); des.encrypt_ctr(ccopy, key, is, os); PTBytes = os.toByteArray(); Assert.assertArrayEquals(MSGBytes, PTBytes); }