So hab das ganze mal als Handy-Application(JAVA ME)
13 ist der Standardkey damit kann man En- und decrypten mit nur einer Methode.
Code:
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
public class CryptIt extends MIDlet implements CommandListener
{
private Display display;
private Form form = new Form("Crypt IT");
private Command crypt = new Command("Crypt", Command.SCREEN, 1);
private Command exit = new Command("Exit", Command.EXIT, 1);
private TextField textfield = new TextField("Standardkey 13:", "", 50, TextField.ANY);
public static String cryptit( String s )
{
StringBuffer ergebnis = new StringBuffer();
int key=13;
for( int i = 0; i < s.length(); i++ )
{
int c = s.charAt( i );
if ( (c >= 'A') && (c <= 'z') )
{
c += key;
if( c > 'z' )
c = 'a' + c % 'z' -1;
if( (c > 'Z') && (c < 'a') )
c = 'A' + c % 'Z' - 1;
}
ergebnis.append( (char) c );
}
return ergebnis.toString();
}
public CryptIt()
{
display = Display.getDisplay(this);
form.addCommand(exit);
form.addCommand(crypt);
form.append(textfield);
form.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command command, Displayable displayable)
{
if (command == crypt)
{
String textin = textfield.getString();
String encrypt = cryptit(textin);
textfield.setString(encrypt);
} else if (command == exit)
{
destroyApp(false);
notifyDestroyed();
}
}
}