j11:verschluesselung:start
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
j11:verschluesselung:start [2023/06/13 15:00] – angelegt Martin Pabst | j11:verschluesselung:start [2023/06/13 15:08] (aktuell) – [Cäsar-Verschlüsselung] Martin Pabst | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
====== Verschlüsselung ====== | ====== Verschlüsselung ====== | ||
+ | ===== Cäsar-Verschlüsselung ===== | ||
< | < | ||
- | <div class=" | + | <div class=" |
<script type=" | <script type=" | ||
Zeile 21: | Zeile 22: | ||
class Cäsar { | class Cäsar { | ||
- | | + | |
| | ||
| | ||
- | this.keyIndex | + | this.keyOffset |
} | } | ||
Zeile 34: | Zeile 35: | ||
char plainCharacter = plaintext.charAt(index); | char plainCharacter = plaintext.charAt(index); | ||
int charIndex = alphabet.indexOf(plainCharacter); | int charIndex = alphabet.indexOf(plainCharacter); | ||
- | | + | |
| | ||
Zeile 50: | Zeile 51: | ||
char plainCharacter = ciphertext.charAt(index); | char plainCharacter = ciphertext.charAt(index); | ||
int charIndex = alphabet.indexOf(plainCharacter); | int charIndex = alphabet.indexOf(plainCharacter); | ||
- | | + | |
| | ||
+ | } | ||
+ | |||
+ | return plaintext; | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | |||
+ | }</ | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Vigenère-Verschlüsselung ===== | ||
+ | < | ||
+ | |||
+ | <div class=" | ||
+ | |||
+ | <script type=" | ||
+ | String schlüssel = Input.readString(" | ||
+ | Vigenere vigenere = new Vigenere(schlüssel); | ||
+ | |||
+ | String plaintext = Input.readString(" | ||
+ | vigenere.encrypt(plaintext); | ||
+ | |||
+ | String ciphertext = vigenere.encrypt(plaintext); | ||
+ | println(" | ||
+ | println(ciphertext); | ||
+ | |||
+ | println(" | ||
+ | println(vigenere.decrypt(ciphertext)); | ||
+ | |||
+ | |||
+ | class Vigenere { | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | this.key = key; | ||
+ | } | ||
+ | |||
+ | | ||
+ | String ciphertext = ""; | ||
+ | int keyIndex = 0; | ||
+ | |||
+ | for (int index = 0; index < plaintext.length(); | ||
+ | char plainCharacter = plaintext.charAt(index); | ||
+ | int charIndex = alphabet.indexOf(plainCharacter); | ||
+ | |||
+ | int keyOffset = alphabet.indexOf(key.charAt(keyIndex)); | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | return ciphertext; | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | | ||
+ | String plaintext = ""; | ||
+ | int keyIndex = 0; | ||
+ | |||
+ | for (int index = 0; index < ciphertext.length(); | ||
+ | char plainCharacter = ciphertext.charAt(index); | ||
+ | int charIndex = alphabet.indexOf(plainCharacter); | ||
+ | |||
+ | int keyOffset = alphabet.indexOf(key.charAt(keyIndex)); | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
} | } | ||
j11/verschluesselung/start.1686668458.txt.gz · Zuletzt geändert: 2023/06/13 15:00 von Martin Pabst