Java Data Encryption Standard (DES) Algorithm

I want to use the methods of DesCipher class.
specifically the encrypt.  It has this definition :

public void encrypt(byte clearText[],
                      int clearOff,
                      byte cipherText[],
                      int cipherOff)
Could anybody know what the parameters mean?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

mbormannConnect With a Mentor Commented:
Sampel example if u have a String of unencrypted data.

String marshiaStr = new String();
marshiaStr+= "This is unencrypted";

use it like
byte [] encyptedData = new byte[marshiaStr.length()];

encrypt(marshiaStr.getBytes() , 0 , encyptedData ,0);

hope it now clears u up.
these r available from
downloaded that and keeping it for refernce.

i dunno anything abt that

Hi mbormann,

I got
thttpd-2_05_tar.tar. Then what next?
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

i also dunno ,will do it when i have free time sometime.
pun intended.
marshiaAuthor Commented:
Thanks mbormann but I already visited the site
before but only got the functions without further explanations on the needed parameters.
From what I can see, I believe the meanings are:

clearText[] - byte array of un encrypted data

int clearOff - offset into clear text at which to start encoding

byte cipherText[] - encrypted data

int cipherOff - offset into encrypted data at which encryption starts

Encrypt probably works something like this:

    /// Encrypt some bytes.
    // The default implementation just calls encrypt(byte) repeatedly.
    // This can be overridden for speed.
    public void encrypt( byte[] clearText, int clearOff, byte[] cipherText, int cipherOff, int len )
      for ( int i = 0; i < len; ++i )
          cipherText[cipherOff + i] = encrypt( clearText[clearOff + i] );

so some data at the start of your block of bytes can be left unencrypted, for whatever reason you choose.

does this make sense?
marshiaAuthor Commented:
Thanks Jod but I want to use the Java class , DesCipher and the method - encrypt which has
4 parameters.
With your example,  with the way I understand it,
I still need to create my own encrypt function.
Nope - the example I gave above is just from the same family of encryption tools to show you what it is doing.

Just use DesCipher and call it like this:

  dataArrayToEncrypt, //as a byte array

  clearoff, //offset into dataArrayToEncrypt to
            // start encrypting data at

  encryptedData, //where encrypted data is stored

  cipheroff // where to start storing encrypted data at in encryptedData

marshiaAuthor Commented:
thanks mbormann,
    I can go on with my program now.

marshiaAuthor Commented:
   congratulations :-)  you've got the points.
hey Jod should have got those man,i didn't pay much attention here.
Don't worry about it mb - just enjoy and know that as it's you I won't be getting the Men In Black to pay you a visit.

This one was a bit of a bummer though... 
Your example was clearer than mine anyway...
i think he still hasn't solved it,marshia?

and Jod ,i don't have points to see the question but i saw it thru my colleague's acct ,OK what is the bummer aside from the fact that "expertmb" is a jumping jiminy sonofagun ?

Yeah i agree that " returning an int as the file length is not a good idea"

also in the same vein  "returning an
int as the String length is not a good idea".

a pet question which i ask many people is ,Is it possible in C++ to create arbitray Strings of 'infinite' length limited only by physical Memory?i think it's limited to (on Intel machines)to 64KB data?

Please I want a answer as i am highly curious.

It is theoratically possible in Java ,ain't it so?but limited by physical Memory
>> jumping jiminy sonofagun

Strong words, softly spoken...;-)

The exact implementation of memory layout for the string class is not defined by the C++ Standard. This architecture is intended to be flexible enough to allow differing implementations by compiler vendors, yet guarantee predictable behavior for users. In particular, the exact conditions under which storage is allocated to hold data for a string object are not defined. String allocation rules were formulated to allow but not require a reference-counted implementation, but whether or not the implementation uses reference counting, the semantics must be the same. To put this a bit differently, in C, every char array occupies a unique physical region of memory. In C++, individual string objects may or may not occupy unique physical regions of memory, but if reference counting is used to avoid storing duplicate copies of data, the individual objects must look and act as though they do exclusively own unique regions of storage. For example:

//: C17:StringStorage.cpp
#include <string>
#include <iostream>
using namespace std;

int main() {
  string s1("12345");
  // Set the iterator indicate the first element
  string::iterator it = s1.begin();
  // This may copy the first to the second or
  // use reference counting to simulate a copy
  string s2 = s1;
  // Either way, this statement may ONLY modify first
  *it = '0';
  cout << "s1 = " << s1 << endl;
  cout << "s2 = " << s2 << endl;
} ///:~

Reference counting may serve to make an implementation more memory efficient, but it is transparent to users of the string class.

In other words, it depends on how it is implemented but possible...

Manipulating basic strings is probably easier in C++ than in Java, because of function overloading. Look here for some examples:
Thanks Jod,

I done completely forgotten ALL my C++ skills whatever they were acquired during college,so had to ask somebody .I can't 'think' in C++ ,that's a big handicap,way too big but i have come to love Java.
i done completed that program today.

import Acme.Crypto.*;

/* This program is dedicated to Ashish Kulkarni,my brother and fellow programmer
Well bro ,we did this ,so take over and do the next step by urself.
For this to work ,download the freely available Acme Crypto package at
if u want it please mail me at,
and i will try to respond under 15 days.

public class EncryptionTest
 private static final int ENC_SIZE = 8;
 private static byte zeroes[] = {0,0,0,0,0,0,0,0};
 private static byte in[] = new byte[ENC_SIZE];
 private static byte out[] = new byte[ENC_SIZE];
 private static byte tempArr[] = new byte[ENC_SIZE];
       zeroes = new byte[ENC_SIZE];
       for(int i=zeroes.length;--i >= 0;)
 public static void main(String[] args) throws Exception
       String unencryptedDataString = "This is unencrypted data String man,testing this out,savvy?";
     byte [] unencrypted_data = unencryptedDataString.getBytes();
       int unencryptLen = unencryptedDataString.length();

       //since 8 is the size of encrypt/decrypt methods
       //of Des3Cipher,we need to pad the original
       //unencrypted byte array

       unencryptLen += (ENC_SIZE-(unencryptLen%ENC_SIZE));
       byte [] encryptedData = new byte[unencryptLen];
       byte [] decryptedData = new byte[unencryptLen];

       //instantiate Des3Cipher with some fixed key
       Des3Cipher cipher= new Des3Cipher("0123456789abcdef");
       for(int eIndx=0;eIndx<unencrypted_data.length;eIndx+=ENC_SIZE )
             cipher.encrypt(in , 0 , tempArr ,0);

       //This proves that at one side u encrypt with a special key
       //at other u use the same one to decrypt,
       //Uh-Oh ,u gotta keep da key in a Seeeecure place man.
       cipher= new Des3Cipher("0123456789abcdef");
       for(int dIndx=encryptedData.length;dIndx>=0;dIndx-=ENC_SIZE )
             cipher.decrypt(out , 0 ,tempArr  ,0);
       //to do a trim is very IMPORTANT,since we havta remove padded spaces.
       System.out.println("\nFINALLY decryptedData='"+new String(decryptedData).trim()+"'");
 private static final byte[] smartCopy(byte [] src,int srcPos,byte [] dst,int dstPos,int len)
       int lenSrcArr=src.length;
       int lenDstArr=dst.length ;
       if(lenSrcArr > lenDstArr)
             if((srcPos+len) > lenSrcArr)
                   System.arraycopy(src,srcPos,dst,0,lenSrcArr - srcPos);
             if((dstPos+len) > lenDstArr)
                   System.arraycopy(src,0,dst,dstPos,lenDstArr - dstPos);
       return dst;
marshiaAuthor Commented:
thanks a lot mbormann,
    you really deserve the points.

marshia :-)
All Courses

From novice to tech pro — start learning today.