File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes crypt algorithm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "crypt algorithm" Watch "crypt algorithm" New topic

crypt algorithm

Zahra Vir

Joined: Dec 04, 2004
Posts: 4
any ideas on how i should do the crypt for the following:

Suppose the key word is feather. Then first remove duplicate letters, yielding feathr, and append the other letters of the alphabet in reverse order. Now encrypt the letters as follows:
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
my first thought would be to fill an array of 26 chars, making a kind of mapping. Then, just use that mapping to encrypt what you need encrypted. Remember that you can cast chars to ints, and visa versa, such that (int)'a'=97, and (char)97='a'.

That ought to get you started.

I've heard it takes forever to grow a woman from the ground
Lee George

Joined: Dec 15, 2004
Posts: 4
I would suggest creating a hashtable with the initial string as the key and the string you wish to convert to as the value. For example, if a converts to t,

Hashtable table = new Hashtable();
table.put("a", "t");

You can then take each letter from the word and us it to extract the value you wish to convert to. For example,

String currentLetter = "a";
String convertedLetter = (String)table.get(currentLetter);

Hope this helps.
I agree. Here's the link:
subject: crypt algorithm
It's not a secret anymore!