25.3
Lösungen
|
Aufgabe 1 |
a |
b |
aXORb |
a+b |
(a+b)mod(10) |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
0 |
10 |
0 |
|
|
|
Aufgabe 2 |
Die
Buchstaben 'A' und 'B' haben die ASCII-Werte 65 und 66. In
Binärdarstellung 1000001 und 1000010. Die XOR-Operation, angewandt auf die
beiden Werte liefert 0000011, in Dezimaldarstellung also 3. Wie die
Tabelle in Kapitel 23.5 ASCII-Kode zeigt, entspricht dies dem '♥'-Zeichen.
|
Aufgabe 3 |
public static String xor(String originalText, String schluessel) {
String geheimText = "";
for (int i = 0; i < originalText.length(); i++){
geheimText += (char) (originalText.charAt(i)^schluessel.charAt(i));
}
return geheimText;
}
|
Aufgabe 4 |
public static String xor(String geheimText, String schluessel) {
String originalText = "";
for (int i = 0; i < geheimText.length(); i++){
originalText += (char) (geheimText.charAt(i)^schluessel.charAt(i));
}
return originalText;
}
|
Aufgabe 5 |
public static String oneTimePad(String originalText, String schluessel){
String geheimText = "";
String key = "";
for (int i = 0; i < schluessel.length(); i += 8){
key += (char) binToInt(schluessel.substring(i,i+8));
}
for (int i = 0; i < originalText.length(); i++){
geheimText += (char) (originalText.charAt(i)^key.charAt(i));
}
return geheimText;
}
Hilfsmethode:
private static int binToInt(String string) throws NumberFormatException{
int zahl=0;
for (int i = 0; i < 8; i++){
zahl += (Integer.parseInt(string.substring(i,i+1))*Math.pow(2,7-i));
}
return zahl;
}
|
Downloads: |
EnCrypt.java -
DeCrypt.java |
zu |
26
RSA-Verschlüsselung
26.1 RSA die Idee |
zur Startseite |
www.pohlig.de (C)
MPohlig 2006 |