Source Code for the Caesar (De)Cipher Applet

=javascript import java.applet.*; import java.awt.*; import java.awt.event.*; public class Beleg4 extends Applet implements ActionListener{ TextField eingabe, eingabe1, eingabe2; String text, code, ausgabe; int czahl; Button b1 = new Button("codieren"); Button b2 = new Button("decodieren"); public void init() { setLayout(null); setBackground(Color.orange); setSize(60,60); b1.setBounds(10,90,90,20); add(b1); b1.addActionListener(this); b2.setBounds(10,130,90,20); add(b2); b2.addActionListener(this); eingabe = new TextField(); eingabe.setBounds(120,90,300,20); eingabe.setBackground(Color.white); add(eingabe); eingabe1 = new TextField(); eingabe1.setBounds(120,130,300,20); eingabe1.setBackgound(Color.white); add(eingabe1); eingabe2 = new TextField(); eingabe2.setBacgound(Color.white); eingabe2.setBounds(120,170,300,20); add(eingabe2); } public static String bearbeiten(String text){ text = text.toLowerCase(); String alphabet = "abcdefghijklmnopqrstuvwxyz"; String newtext=""; for(int i=0; i<text.length();i++){ if(alphabet.indexOf(text.charAt(i))!=-1) newtext = newtext + text.charAt(i); } return newtext; } public void actionPerformed(ActionEvent ae){ Object quelle = ae.getSource(); if(quelle == b1){ text = bearbeiten(eingabe.getText()); czahl = Integer.parseInt(eingabe1.getText()); code = Caesar.codieren(text,czahl); eingabe2.setText(code); } else if(quelle == b2){ code = bearbeiten(eingabe2.getText()); czahl = Integer.parseInt(eingabe1.getText()); text = Caesar.decodieren(code,czahl); eingabe.setText(text); } } public void paint(Graphics g) { g.drawString("decodierter Text",120,85); g.drawString("Codezahl",120,125); g.drawString("codierter Text",120,165); Font f = new Font("Arial",Font.BOLD+Font.ITALIC,16); //g.setColor(Color.red); g.setFont(f); g.drawString("Caesar Chiffriermaschine",10,40); } } public class Caesar{ /** * Diese Methode codiert den Text. */ public static String codieren(String newtext,int schlüssel) { byte[]array = newtext.getBytes(); //**Text wird in ein Bytearray gepackt, um den Asccicode lesen zu können. int intzahl; byte[]newarray = new byte[array.length]; for(int i = 0; i < array.length; i++){ intzahl = (int) array[i]; //**Bytezahl wird in Intzahl umgewandelt, weil byte nur bis 127 speichert. intzahl = intzahl + schlüssel; if(intzahl>122) intzahl = intzahl - 26; byte bytezahl = new Integer(intzahl).byteValue(); newarray[i] = bytezahl; } String code = new String(newarray); return code; } public static String decodieren(String code, int schlüssel) { byte[]array = code.getBytes(); byte[]newarray = new byte[array.length]; for(int i = 0; i < array.length; i++){ int intzahl = (int) array[i]; intzahl = intzahl - schlüssel; if( intzahl<97){ intzahl = intzahl + 26; } byte bytezahl = new Integer(intzahl).byteValue(); newarray[i] = bytezahl; } String newtext = new String(newarray); return newtext; } }