Could someone help me please

I am doing a piece of code in RMI here is what i have come up with up to now:

publicclass cipherimpl

extends java.rmi.server.UnicastRemoteObject

implements cipher{

public cipherimpl()

throws java.rmi.RemoteException{

super();

}

char[] tempArray;

int b = 3;

public String encrypt(String nameofString,int b)

throws java.rmi.RemoteException{

tempArray = nameofString.toCharArray();

char c =char[0];

int c1 = (int) c;

c2 = c1+b;

return nameofString;

}

public String decrypt(String nameofString,int b)

throws java.rmi.RemoteException{

tempArray = nameofString.toCharArray();

char d =char[0];

int d1 = (int) d;

d2 = d2-b;

return nameofString;

}

}

I also have a code called chiper.java which defines the two methods encrypt and decrypt.

For the impl file i need to make it use the Caesar Cipher method where there is an integer and this integer is used to encrytp a word so if the integer is equal to 1 each of the letters in the word are incremented by 1 so if the word "HELLO" was inputted the output would be "IFMMP" if u get what i mean but i am finding it difficult to put into code.

Could someone give me a few clues please.

Thanx

MARK

[2369 byte] By [Liver_Lad] at [2007-9-30 23:27:47]
# 1
The code is not complete as you can see i have just put a brief example down but it is not really in JAVA code at the moment
Liver_Lad at 2007-7-7 14:03:31 > top of Java-index,Security,Event Handling...
# 2
So what help do you need?
sabre150 at 2007-7-7 14:03:31 > top of Java-index,Security,Event Handling...
# 3

why are you messing around with RMI from the off, when you don't appear to have a grasp of what is required to do this is a non-distributed program? Do that first. Get the barrel-shifting of the text working first, and then that can be one class. You can use this on your server later when you get to the point to tackle it in a distributed manner.

javajugs at 2007-7-7 14:03:31 > top of Java-index,Security,Event Handling...
# 4

It is a task i have been given to do.

I have studied Java but still don't get the grasp of it

the main help i need with this piece of code is how to tell the program to increment a word by 1 when encrypt method is called

And to decrement the word by 1 when the decrypt method is called.

I would be honoured if you could help me

Liver_Lad at 2007-7-7 14:03:31 > top of Java-index,Security,Event Handling...
# 5

mate, i wasn't saying why are you messing with RMI, what I mean was why are you trying to do it all at once. Try to break down the problem. If all you want to do is to increment the character by one then the simplest way to do it is to set up an array of all the letters of the alphabet. Iterate over the string getting each character. Look it up in the array, and then get the next one, and add that to an output StringBuffer. When you have reached the end of the input string, toString() the StringBuffer, and you are done.

Fundamentally, programming is all about breaking problems up. If you try and look at everything at once you will either go mad, or not be able to cope.

HTH

javajugs at 2007-7-7 14:03:31 > top of Java-index,Security,Event Handling...
# 6

Oh and for decrypt, just get the previous one!

Encryption and Decryption share some behaviour e.g. the iterating over the string, the StringBuffer, the array lookup etc. You can farm this out into one single method, and then only the direction in which you look for the next character will be different in the encrypt and decrypt methods.

javajugs at 2007-7-7 14:03:31 > top of Java-index,Security,Event Handling...
# 7
Thanx alot javajugsI needed that i do seem to try and do everything at once and usually get stressed which is probably not new with computingalways stressedcheers mate will give it another whirl:-)
Liver_Lad at 2007-7-7 14:03:31 > top of Java-index,Security,Event Handling...
# 8

Right. Get the CipherBean working without RMI. Once you have that working, just wrap it in RMI or, better yet, let your RMI server instantiate your CipherBean and just use it to accomplish the task.

It's called "decomposition" or "divide and conquer". Solve big problems by dividing them up into smaller, more manageable pieces.

%

duffymo at 2007-7-7 14:03:31 > top of Java-index,Security,Event Handling...