• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

crypt algorithm

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Skool. Stay in. Smartness. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic