aspose file tools*
The moose likes Beginning Java and the fly likes Encryption Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Encryption" Watch "Encryption" New topic
Author

Encryption

Shelly Biswal
Greenhorn

Joined: Sep 07, 2007
Posts: 17
Hi all,
i urgently need help....

i need to write a program which will encrypt a string using a character mapping provided in a file.
The input to your program will be a file which contains mapping for characters.
For E.g. A D
B R
S H
with this mapping if the string has an 'A' then it should be replaced by 'D' etc...
I have to use java exception handling to handle any exceptions like "File not found","File format not correct", "No mapping Present" etc....
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

OK, so you've told us your assignment. Now you have to show us what you've done so far. If you haven't been able to start: reading in the data file would be a good first step!

As with all programming: take little steps. Write the code to open a file, make sure it compiles, test it. Then add code to read a line and print it out. Make sure it compiles, and then test it. Then write a loop to read all the lines, and test that. Take it one step at a time, and it will be easy.


[Jess in Action][AskingGoodQuestions]
Shelly Biswal
Greenhorn

Joined: Sep 07, 2007
Posts: 17
I wrote the code everyting wrks fine except line /*1*/ - the output is always null dont know why.. pls explain



ReadCharacterMapping.java

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

You're storing the data using String objects as keys in the map, but you're trying to look it up using Character objects -- different kinds of objects, so they aren't interchangeable. Instead of get(s.charAt(i)), use get(String.valueOf(s.charAt(i))) .
 
Don't get me started about those stupid light bulbs.
 
subject: Encryption