DES Program

2 comments - Post a comment

/*************** DES **************
*The program listed below,
takes the DES key input and a text string (to be encrypted) from the program itself (not from a file),

encrypts the string (to produce the ciphertext), writes the key and the ciphertext to a file DES.out, decrypts the ciphertext (still in computer memory), and writes the resulting plaintext string to the file.

In this example, we see see the following three numbers:

DES key: 3812A419C63BE771

Plaintext: 0101010101010101 0102030405060708 090A0B0C0D0E0F10 1112131415161718

Ciphertext: 3A2EAD12F475D82C 1FC97BB9A6D955E1 EA5541946BB4F2E6 F29555A6E8F1FB3C */

import java.math.*;
import cryptix.util.core.BI;
import cryptix.util.core.ArrayUtil;
import cryptix.util.core.Hex;
import cryptix.provider.key.*;

class testDES {

public static void main (String[] args) {

try {
FileOutputStream outFile1 = new FileOutputStream("DES.out");
// Note: PrintStream is deprecated, but still works fine in jdk1.1.7b
PrintStream output1 = new PrintStream(outFile1);

// convert a string to a DES key and print out the result
RawSecretKey key2 = new RawSecretKey("DES",Hex.fromString("3812A419C63BE771"));
RawKey rkey = (RawKey) key2;
byte[] yval = rkey.getEncoded();
BigInteger Bkey = new BigInteger(yval);
String w = cryptix.util.core.BI.dumpString(Bkey);
output1.println("The Encryption Key = " + w);

// use the DES key to encrypt a string
Cipher des=Cipher.getInstance("DES/ECB/NONE","Cryptix");
byte[] ciphertext = des.crypt(Hex.fromString("01010101010101010102030405060708090A0B0C0D0E0F101112131415161718"));

// print out length and representation of ciphertext
output1.println("ciphertext.length = " + ciphertext.length);

BigInteger Bciph = new BigInteger(ciphertext);
w = cryptix.util.core.BI.dumpString(Bciph);
output1.println("Ciphertext for DES encryption = " + w);

// decrypt ciphertext
ciphertext = des.crypt(ciphertext);
output1.println("plaintext.length = " + ciphertext.length);

// print out representation of decrypted ciphertext
Bciph = new BigInteger(ciphertext);
w = cryptix.util.core.BI.dumpString(Bciph);
output1.println("Plaintext for DES encryption = " + w);

output1.println(" ");

} catch (Exception e) {
System.err.println("Caught exception " + e.toString());


This Post has 2 Comments Add your own!
Anonymous - August 29, 2011 at 9:15 PM

I am here to help get your web site off to an excellent start off. Don't be 1 of those that wished they had accomplished it better the very first time, then just take on the task, and price, of starting over. Your web site displays what you as well as your organization or pastime are all about.

I'm able to offer low-cost, user-friendly, custom created internet sites for a vast variety of businesses, organizations and teams.Additionally, it should not cost a lot of money to obtain you began. I am going to assist manual you via the method as well as alert you after i believe you could be acquiring in over your head, or past your spending budget.

Listed below are some hight high quality services for any resonable cost:

Front-End Development
Custom web site design
Affordable web site design
E-Commerce website design
Corporate Website Design
Innovative website design
Static Web Design
Website maintenance
Web site re-designs
SEO Services
Logo Design

Please look around the site for further information about the [url=]freelance web designer[/url] services that I am able to offer and to see examples of websites that I have designed



hanan elzubair - June 5, 2012 at 1:11 PM

thank alot

Post a Comment