| | |
Java Cipher Help??
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2006
Posts: 3
Reputation:
Solved Threads: 0
Hi Guys, wonder if any one can help??
I have been asigned some home work to make a CaesarCipher class, listed below, where by there is a test class below which would need to be passed to it. I have figured out the first bit but cant debugg and get it to work. Hope you can help
Tom Keys
//First Class file
public class CaesarTest {
public static void main( String[] args ) {
CaesarCipher c = new CaesarCipher( 10 );
String output;
output = c.encrypt( "The quick brown fox jumps over the lazy dog" );
System.out.println( output );
output = c.decrypt( output );
System.out.println( output );
}
}
//Second Class File
public class CaesarCipher {
private int key;
public CaesarCipher( int inKey ) {
key = inKey;
}
public String encrypt( String s ) {
int lengthOfString = s.length();
StringBuffer encrypted = new StringBuffer();
for (int i=0; i< lengthOfString; i++) {
char tempChar = s.charAt(i);
encrypted.append( encrypt( tempChar ) );
}
return i;
}
//public String decrypt( String s ) {
// Decrypt the argument a character at a time & return the result
//}
private char encrypt( char c ) {
c = charact;
//Encrypt the argument & return the result
//char charact = stringName.getCharAt(i);
charact = charact + key;
outString.append(charact);
}
//private char decrypt( char c ) {
// Decrypt the argument & return the result
//}
}
I have been asigned some home work to make a CaesarCipher class, listed below, where by there is a test class below which would need to be passed to it. I have figured out the first bit but cant debugg and get it to work. Hope you can help
Tom Keys
//First Class file
public class CaesarTest {
public static void main( String[] args ) {
CaesarCipher c = new CaesarCipher( 10 );
String output;
output = c.encrypt( "The quick brown fox jumps over the lazy dog" );
System.out.println( output );
output = c.decrypt( output );
System.out.println( output );
}
}
//Second Class File
public class CaesarCipher {
private int key;
public CaesarCipher( int inKey ) {
key = inKey;
}
public String encrypt( String s ) {
int lengthOfString = s.length();
StringBuffer encrypted = new StringBuffer();
for (int i=0; i< lengthOfString; i++) {
char tempChar = s.charAt(i);
encrypted.append( encrypt( tempChar ) );
}
return i;
}
//public String decrypt( String s ) {
// Decrypt the argument a character at a time & return the result
//}
private char encrypt( char c ) {
c = charact;
//Encrypt the argument & return the result
//char charact = stringName.getCharAt(i);
charact = charact + key;
outString.append(charact);
}
//private char decrypt( char c ) {
// Decrypt the argument & return the result
//}
}
![]() |
Similar Threads
- Need help with Caesar Cipher program (Java)
- Java Encryption error (Java)
- Java 3D (Java)
- Java Expert (Needed) (Java)
- Java Chat Reboots (Java)
Other Threads in the Java Forum
- Previous Thread: Really Beginning problem.
- Next Thread: Warning Message DialogBox
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse encode equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number object online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions rotatetext scanner score screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows xstream






