• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

crypt algorithm

 
Zahra Vir
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
abcdefghijklmnopqrstuvwxyz
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
feathrzyxwvusqponmlkjigdcb
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lee George
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic