Einzelnen Beitrag anzeigen
Alt 18.09.08, 10:38   #38 (permalink)
root.tea
 
Registriert seit: 11.09.08
root.tea Leistung: Facit NTK
Likes: 0
Standard

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();
    	}
  	}
}
root.tea ist offline   Mit Zitat antworten
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61