• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

crypt algorithm

 
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
 
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.
 
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.
 
    Bookmark Topic Watch Topic
  • New Topic