Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
| gf_informatik:verschluesselung:codierung [2026-03-19 08:54] – [Aufgabe 1: ASCII-Tabelle erzeugen] hof | gf_informatik:verschluesselung:codierung [2026-04-09 06:40] (aktuell) – hof | ||
|---|---|---|---|
| Zeile 11: | Zeile 11: | ||
| In Python können wir einen Buchstaben mit der `ord()` Funktion in die entsprechende ASCII-Zahl verwandeln. `ord` steht für _ordinal value_, also die Ordnungszahl eines Buchstabens in der ASCII-Textcodierung. | In Python können wir einen Buchstaben mit der `ord()` Funktion in die entsprechende ASCII-Zahl verwandeln. `ord` steht für _ordinal value_, also die Ordnungszahl eines Buchstabens in der ASCII-Textcodierung. | ||
| - | < | + | < |
| < | < | ||
| Zeile 49: | Zeile 49: | ||
| ``` | ``` | ||
| - | < | + | < |
| ++++Lösung: | ++++Lösung: | ||
| < | < | ||
| Zeile 88: | Zeile 88: | ||
| `01010011 01110101 01100111` | `01010011 01110101 01100111` | ||
| - | < | + | < |
| ++++Lösung: | ++++Lösung: | ||
| `00111011 00010100 00001011` | `00111011 00010100 00001011` | ||
| Zeile 101: | Zeile 101: | ||
| - Mit der ASCII-Tabelle kannst du nun die Binärzahlen in Buchstaben wandeln und erhälst den Klartext. | - Mit der ASCII-Tabelle kannst du nun die Binärzahlen in Buchstaben wandeln und erhälst den Klartext. | ||
| - | < | + | < |
| ++++Lösung: | ++++Lösung: | ||
| Der Klartext Lautet: '' | Der Klartext Lautet: '' | ||
| Zeile 124: | Zeile 124: | ||
| Mit diesen Informationen solltest du ein Programm schreiben können, das den folgenden Text entschlüsselt. | Mit diesen Informationen solltest du ein Programm schreiben können, das den folgenden Text entschlüsselt. | ||
| - | | + | |
| - | * die Buchstaben des Schlüssels werden alle 10 Buchstaben wieder | + | Hinweise: |
| - | * mit `split()` kann ein String in einzelne Wörter geteilt werden: `for word in "eins zwei drei" | + | |
| + | * Wandle den Schlüssel in eine Folge von ASCII-codierten Zahlen um: `[82, 79, 77, ...]`! | ||
| + | * Mit `split()` kann ein String in einzelne Wörter geteilt werden: `for word in "eins zwei drei" | ||
| + | * Wandle das Chiffrat in eine Liste von Zahlen um: `[22, 38, 40, ...]`! | ||
| + | * XOR-kombiniere nun immer eine Zahl aus dem Chiffrat mit einer Zahl aus dem Schlüssel! | ||
| + | * Die Buchstaben des Schlüssels werden alle 10 Buchstaben wieder von vorne verwendet. | ||
| + | * Wandle die resultierende Zahl mit `chr()` in Buchstaben um! | ||
| ``` | ``` | ||
| Zeile 134: | Zeile 140: | ||
| ``` | ``` | ||
| - | < | + | < |
| ++++Lösung: | ++++Lösung: | ||
| <code python decrypt.py> | <code python decrypt.py> | ||
| Zeile 162: | Zeile 168: | ||
| ++++ | ++++ | ||
| </ | </ | ||
| - | |||
| - | |||
| ### Aufgabe 5 (optional) | ### Aufgabe 5 (optional) | ||
| Zeile 188: | Zeile 192: | ||
| ++++ | ++++ | ||
| - | < | + | < |
| ++++Full Block Coder:| | ++++Full Block Coder:| | ||
| Zeile 274: | Zeile 278: | ||
| </ | </ | ||
| - | < | + | < |
| ++++ Lösung| | ++++ Lösung| | ||
| - | <code python> | + | <html>< |
| + | # In normal python: pip install opencv-python numpy | ||
| + | import micropip | ||
| + | await micropip.install([" | ||
| import cv2 as cv | import cv2 as cv | ||
| import numpy as np | import numpy as np | ||
| Zeile 283: | Zeile 291: | ||
| key = " | key = " | ||
| - | img = cv.imread('encryption/ | + | img_url |
| + | # In vanilla python, use urllib.request.urlopen(img_url) | ||
| + | from pyodide.http import pyfetch | ||
| + | response = await pyfetch(img_url) | ||
| + | data = await response.bytes() | ||
| + | |||
| + | arr = np.asarray(bytearray(data), | ||
| + | img = cv.imdecode(arr, | ||
| # Note that the key length (in bits) is not byte-aligned (not a multiple of 8). | # Note that the key length (in bits) is not byte-aligned (not a multiple of 8). | ||
| print(img.size) | print(img.size) | ||
| print(len(key)) | print(len(key)) | ||
| - | + | ||
| - | # Repeat the key as often as necessary to match the image length. | + | # Repeat the key as often as necessary to match the image length. |
| key = key * math.ceil(img.size*8 / len(key)) | key = key * math.ceil(img.size*8 / len(key)) | ||
| key_offset = 0 | key_offset = 0 | ||
| + | |||
| # Process each pixel | # Process each pixel | ||
| for x in range(img.shape[0]): | for x in range(img.shape[0]): | ||
| Zeile 306: | Zeile 322: | ||
| img[x,y] = b, g, r | img[x,y] = b, g, r | ||
| key_offset = key_offset + 24 | key_offset = key_offset + 24 | ||
| + | |||
| cv.imshow(' | cv.imshow(' | ||
| cv.waitKey() | cv.waitKey() | ||
| - | </code> | + | </bottom-editor></ |
| ++++ | ++++ | ||
| </ | </ | ||