ProgramWindowJava

Encrypt / Decrypt homework help

Hello
I got a hw assignment in which I have to ask the user weather they want to encrypt or decrypt. then it asks them a value of N
to do the encrypt I take the ASCII value and add N to it. Finaly I ask them a sentence.

all has gone well except one issue. In this class, code follows, I have the methods to en/decrypt the text. when I run I get a out of memory error on the "sbb.append(aChar);" line

Thanks for any and all help!


import java.text.*;
import java.lang.*;
import java.io.*;
import javax.swing.*;

public class Calculator {

private String choice;
private int N;
String results;
char aChar;
String test;

public void setN(int n){
N = n;
}

public void encrypt(String e){

StringBuffer sbb = new StringBuffer("");

choice = e;
StringBuffer sb = new StringBuffer(choice);
int length = choice.length();

int i = 0;
while( i < length){
aChar = choice.charAt(i);
aChar += N;
sbb.append(aChar);
}
test = sbb.toString();
}

public void decrypt(String d){

StringBuffer sbb = new StringBuffer("");

choice = d;
StringBuffer sb = new StringBuffer(choice);
int length = choice.length();

int i = 0;
while( i < length){
aChar = choice.charAt(i);
aChar -= N;
sbb.append(aChar);
}
test = sbb.toString();

}


public String sendDisplay(){
results = test;
return results;
}

}

Replay:Encrypt / Decrypt homework help
Quote:
Originally posted by tnb3993
// Infinite loop here:

int i = 0;
while( i < length){
aChar = choice.charAt(i);
aChar += N;
sbb.append(aChar);
}
test = sbb.toString();
}

public void decrypt(String d){

StringBuffer sbb = new StringBuffer("");

choice = d;
StringBuffer sb = new StringBuffer(choice);
int length = choice.length();



// Infinite loop here also
int i = 0;
while( i < length){
aChar = choice.charAt(i);
aChar -= N;
sbb.append(aChar);
}
test = sbb.toString();

}

}


You might want to consider doing something with "i", i++ would probably work

Good luck.

Replay:Encrypt / Decrypt homework help
once again I turn something that is way to easy i++ and forget it

thanks

[Previous] Help!! using recursion to search an array
[Next] Menus

Google


Java

Menus
help!!!!!!!!!!!!!!!
How to access JSpinner's JTextField?
easy questions
recursion/iterator problem
repainting the whole frame??
Help Wih Chessboard Problem
Format US currency
Applet:How do I get a background image.
ArrayList printout?
Get rid of that comma in my JSpinner!!!
calling other classes
Variables not visable?
return statement trouble
how to setup showConfirmDialog?
Bumper car program
how to configure showConfirmDialog
database connection to jsp page
database connection to jsp page
Help with JEditorPane