Making A into M for a secret code making app

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Making A into M for a secret code making app

Postby norton5315 » Thu Jul 08, 2010 2:22 am

I'm new to Java (I'm catching on) and developing for Android and I'm not sure how to put what is about to be explained into Java code.
I am making an app that takes text and makes it into a scrambled code that can later be unscrambled. What I can't figure out is, for example: take the letter A and make it the letter M. And so on with the rest of the letters. So that if someone typed "I am hiding" the app would turn it into "U my tupus". Then the same app on a different device could decode "U my tupus" back into "I am hiding".
norton5315
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Jul 08, 2010 2:04 am

Top

Re: Making A into M for a secret code making app

Postby anarche » Thu Jul 08, 2010 7:20 am

Char.valueOf(Integar.parseInt('A') + <howevermanytom>);
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: Making A into M for a secret code making app

Postby steven_h » Thu Jul 22, 2010 4:30 pm

Use a Hash Map.

Code: Select all
String alphabet = "abcdefghijklmnopqrstuvwxyz";
String encodedAlphabet = "mnopqrstuvwxyzabcdefghijkl";
HashMap<String, String> cypher = new HashMap<String, String>();

for(int i = 0; i < alphabet.length(); i++) {
   cypher.put(alphabet.substring(i, i+1), encodedAlphabet.substring(i, i+1));
}

etc....


Then you use
Code: Select all
cypher.get("a")
and it will give you a M whenever you are doing your parsing.
HashMap Java API
steven_h
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Jul 22, 2010 4:21 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests