Hallo ich Programmire gerade an einem Polybios Chiffre und will das Char Array erweitern.
Wie kann ich das da ich mehr als 10 Werte baruche?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Polybios extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
char miyao[][] = { { ' ', '1', '2', '3', '4', '5' },
{ '1', 'a', 'b', 'c', 'd', 'e' },
{ '2', 'f', 'g', 'h', 'i', 'k' },
{ '3', 'l', 'm', 'n', 'o', 'p' },
{ '4', 'q', 'r', 's', 't', 'u' },
{ '5', 'v', 'w', 'x', 'y', 'z' },
{ '6', 'ä', 'ö', 'ü', 'ß', ' ' },
{ '7', '1', '2', '3', '4', '5' },
{ '8', '6', '7', '8', '9', '0' },
{ '9', '1', '2', '3', '4', '5' },
{ '10', 'A', 'B', 'C', 'D', 'E' },
{ '11', 'F', 'G', 'H', 'I', 'K' },
{ '12', 'L', 'M', 'N', 'O', 'P' },
{ '13', 'Q', 'R', 'S', 'T', 'U' },
{ '14', 'V', 'W', 'X', 'Y', 'Z' },
{ '15', 'Ä', 'Ö', 'Ü', 'ø', 'ë' }};
char buf[];
String s1 = new String();
String x, y;
int i;
int j;
int l;
int n;
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JLabel la1 = new JLabel("Polybios");
JTextArea text1 = new JTextArea(8, 4);
JTextArea text2 = new JTextArea(8, 4);
JButton btn1 = new JButton("Verschlüsseln");
JButton btn2 = new JButton("Etschlüsseln");
JButton btn3 = new JButton("Löschen");
public Polybios() {
setSize(500, 250);
setTitle("polybios");
la1.setBorder(BorderFactory.createEtchedBorder());
la1.setOpaque(true);
JScrollPane jsp1 = new JScrollPane(text1);
JScrollPane jsp2 = new JScrollPane(text2);
p1.add(la1);
p2.add(btn1);
p2.add(btn2);
p2.add(btn3);
Container contentPane = this.getContentPane();
contentPane.setLayout(new GridLayout(4, 1));
contentPane.add(p1);
contentPane.add(jsp1);
contentPane.add(p2);
contentPane.add(jsp2);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn1) {
jiami();
} else if (e.getSource() == btn2) {
jiemi();
} else if (e.getSource() == btn3) {
text1.setText("");
text2.setText("");
}
}
public static void main(String args[]) {
new Polybios();
}
void jiami() {
s1 = text1.getText();
s1 = s1.toLowerCase();
l = s1.length();
buf = s1.toCharArray();
for (n = 0; n < l; n++) {
for (i = 1; i < 9; i++) {
for (j = 1; j < 6; j++)
if (miyao[j] == buf[n]) {
x = String.valueOf(miyao[0]);
y = String.valueOf(miyao[0][j]);
text2.append(x);
text2.append(y);
}
}
if (buf[n] == 'j') {
x = String.valueOf('j');
y = String.valueOf('j');
text2.append(x);
text2.append(y);
}
}
}
void jiemi() {
s1 = text1.getText();
s1 = s1.toLowerCase();
l = s1.length();
buf = s1.toCharArray();
for (n = 0; n < l - 1; n = n + 2) {
for (i = 1; i < 9; i++)
if (miyao[0] == buf[n]) {
for (j = 1; j < 6; j++)
if (miyao[0][j] == buf[n + 1]) {
x = String.valueOf(miyao[j]);
text2.append(x);
}
}
if (buf[n] == 'j' && buf[n + 1] == 'j') {
x = String.valueOf('j');
text2.append(x);
}
}
}
}
Wie kann ich das da ich mehr als 10 Werte baruche?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Polybios extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
char miyao[][] = { { ' ', '1', '2', '3', '4', '5' },
{ '1', 'a', 'b', 'c', 'd', 'e' },
{ '2', 'f', 'g', 'h', 'i', 'k' },
{ '3', 'l', 'm', 'n', 'o', 'p' },
{ '4', 'q', 'r', 's', 't', 'u' },
{ '5', 'v', 'w', 'x', 'y', 'z' },
{ '6', 'ä', 'ö', 'ü', 'ß', ' ' },
{ '7', '1', '2', '3', '4', '5' },
{ '8', '6', '7', '8', '9', '0' },
{ '9', '1', '2', '3', '4', '5' },
{ '10', 'A', 'B', 'C', 'D', 'E' },
{ '11', 'F', 'G', 'H', 'I', 'K' },
{ '12', 'L', 'M', 'N', 'O', 'P' },
{ '13', 'Q', 'R', 'S', 'T', 'U' },
{ '14', 'V', 'W', 'X', 'Y', 'Z' },
{ '15', 'Ä', 'Ö', 'Ü', 'ø', 'ë' }};
char buf[];
String s1 = new String();
String x, y;
int i;
int j;
int l;
int n;
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JLabel la1 = new JLabel("Polybios");
JTextArea text1 = new JTextArea(8, 4);
JTextArea text2 = new JTextArea(8, 4);
JButton btn1 = new JButton("Verschlüsseln");
JButton btn2 = new JButton("Etschlüsseln");
JButton btn3 = new JButton("Löschen");
public Polybios() {
setSize(500, 250);
setTitle("polybios");
la1.setBorder(BorderFactory.createEtchedBorder());
la1.setOpaque(true);
JScrollPane jsp1 = new JScrollPane(text1);
JScrollPane jsp2 = new JScrollPane(text2);
p1.add(la1);
p2.add(btn1);
p2.add(btn2);
p2.add(btn3);
Container contentPane = this.getContentPane();
contentPane.setLayout(new GridLayout(4, 1));
contentPane.add(p1);
contentPane.add(jsp1);
contentPane.add(p2);
contentPane.add(jsp2);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn1) {
jiami();
} else if (e.getSource() == btn2) {
jiemi();
} else if (e.getSource() == btn3) {
text1.setText("");
text2.setText("");
}
}
public static void main(String args[]) {
new Polybios();
}
void jiami() {
s1 = text1.getText();
s1 = s1.toLowerCase();
l = s1.length();
buf = s1.toCharArray();
for (n = 0; n < l; n++) {
for (i = 1; i < 9; i++) {
for (j = 1; j < 6; j++)
if (miyao[j] == buf[n]) {
x = String.valueOf(miyao[0]);
y = String.valueOf(miyao[0][j]);
text2.append(x);
text2.append(y);
}
}
if (buf[n] == 'j') {
x = String.valueOf('j');
y = String.valueOf('j');
text2.append(x);
text2.append(y);
}
}
}
void jiemi() {
s1 = text1.getText();
s1 = s1.toLowerCase();
l = s1.length();
buf = s1.toCharArray();
for (n = 0; n < l - 1; n = n + 2) {
for (i = 1; i < 9; i++)
if (miyao[0] == buf[n]) {
for (j = 1; j < 6; j++)
if (miyao[0][j] == buf[n + 1]) {
x = String.valueOf(miyao[j]);
text2.append(x);
}
}
if (buf[n] == 'j' && buf[n + 1] == 'j') {
x = String.valueOf('j');
text2.append(x);
}
}
}
}