j11:verschluesselung:start
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
j11:verschluesselung:start [2023/06/13 15:02] – Martin Pabst | j11:verschluesselung:start [2023/06/13 15:08] (aktuell) – [Cäsar-Verschlüsselung] Martin Pabst | ||
---|---|---|---|
Zeile 22: | Zeile 22: | ||
class Cäsar { | class Cäsar { | ||
- | | + | |
| | ||
| | ||
- | this.keyIndex | + | this.keyOffset |
} | } | ||
Zeile 35: | Zeile 35: | ||
char plainCharacter = plaintext.charAt(index); | char plainCharacter = plaintext.charAt(index); | ||
int charIndex = alphabet.indexOf(plainCharacter); | int charIndex = alphabet.indexOf(plainCharacter); | ||
- | | + | |
| | ||
Zeile 51: | Zeile 51: | ||
char plainCharacter = ciphertext.charAt(index); | char plainCharacter = ciphertext.charAt(index); | ||
int charIndex = alphabet.indexOf(plainCharacter); | int charIndex = alphabet.indexOf(plainCharacter); | ||
- | | + | |
| | ||
Zeile 74: | Zeile 74: | ||
<script type=" | <script type=" | ||
- | char schlüssel = Input.readChar(" | + | String |
- | Cäsar cäsar | + | Vigenere vigenere |
String plaintext = Input.readString(" | String plaintext = Input.readString(" | ||
- | cäsar.encrypt(plaintext); | + | vigenere.encrypt(plaintext); |
- | String ciphertext = cäsar.encrypt(plaintext); | + | String ciphertext = vigenere.encrypt(plaintext); |
println(" | println(" | ||
println(ciphertext); | println(ciphertext); | ||
println(" | println(" | ||
- | println(cäsar.decrypt(ciphertext)); | + | println(vigenere.decrypt(ciphertext)); |
- | class Cäsar | + | class Vigenere |
- | int keyIndex; | + | String key; |
| | ||
- | | + | |
- | this.keyIndex | + | this.key = key; |
} | } | ||
| | ||
String ciphertext = ""; | String ciphertext = ""; | ||
+ | int keyIndex = 0; | ||
for (int index = 0; index < plaintext.length(); | for (int index = 0; index < plaintext.length(); | ||
char plainCharacter = plaintext.charAt(index); | char plainCharacter = plaintext.charAt(index); | ||
int charIndex = alphabet.indexOf(plainCharacter); | int charIndex = alphabet.indexOf(plainCharacter); | ||
- | charIndex = (charIndex + keyIndex) % alphabet.length(); | + | |
+ | int keyOffset = alphabet.indexOf(key.charAt(keyIndex)); | ||
+ | |||
+ | charIndex = (charIndex + keyOffset) % alphabet.length(); | ||
| | ||
+ | | ||
} | } | ||
Zeile 115: | Zeile 120: | ||
| | ||
String plaintext = ""; | String plaintext = ""; | ||
+ | int keyIndex = 0; | ||
for (int index = 0; index < ciphertext.length(); | for (int index = 0; index < ciphertext.length(); | ||
char plainCharacter = ciphertext.charAt(index); | char plainCharacter = ciphertext.charAt(index); | ||
int charIndex = alphabet.indexOf(plainCharacter); | int charIndex = alphabet.indexOf(plainCharacter); | ||
- | charIndex = (charIndex - keyIndex | + | |
+ | int keyOffset = alphabet.indexOf(key.charAt(keyIndex)); | ||
+ | charIndex = (charIndex - keyOffset | ||
| | ||
+ | | ||
} | } | ||
j11/verschluesselung/start.1686668539.txt.gz · Zuletzt geändert: 2023/06/13 15:02 von Martin Pabst