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 [2025-03-24 09:04] – [Aufgabe 1: ASCII-Tabelle erzeugen] hof | gf_informatik:verschluesselung:codierung [2025-04-01 14:30] (aktuell) – hof | ||
|---|---|---|---|
| Zeile 54: | Zeile 54: | ||
| ++++Lösung: | ++++Lösung: | ||
| < | < | ||
| - | print(f" | + | print(f" |
| def printTable(): | def printTable(): | ||
| Zeile 90: | Zeile 90: | ||
| `01010011 01110101 01100111` | `01010011 01110101 01100111` | ||
| - | < | + | < |
| ++++Lösung: | ++++Lösung: | ||
| `00111011 00010100 00001011` | `00111011 00010100 00001011` | ||
| Zeile 136: | Zeile 136: | ||
| ``` | ``` | ||
| - | < | + | < |
| ++++Lösung: | ++++Lösung: | ||
| <code python decrypt.py> | <code python decrypt.py> | ||
| Zeile 164: | Zeile 164: | ||
| ++++ | ++++ | ||
| </ | </ | ||
| + | |||
| ### Aufgabe 5 (optional) | ### Aufgabe 5 (optional) | ||
| Zeile 196: | Zeile 197: | ||
| * `string.encode()` und `bytes.decode()` ([[https:// | * `string.encode()` und `bytes.decode()` ([[https:// | ||
| - | <code python block_coder.py> | + | <HTML>< |
| - | def textToBytes(text): | + | |
| """ | """ | ||
| numbers = [] | numbers = [] | ||
| Zeile 272: | Zeile 272: | ||
| 00111010 00100001 01101110 00100001 00100110 00100011 00100101 | 00111010 00100001 01101110 00100001 00100110 00100011 00100101 | ||
| 01101110 00110010 00100100 00100011 00110111 01101111""" | 01101110 00110010 00100100 00100011 00110111 01101111""" | ||
| - | print(decrypt(ciphertext, | + | print(decrypt(ciphertext, |
| + | ++++ | ||
| + | </ | ||
| + | |||
| + | <nodisp 1> | ||
| + | ++++ Lösung| | ||
| + | <code python> | ||
| + | import cv2 as cv | ||
| + | import numpy as np | ||
| + | import math | ||
| + | |||
| + | key = " | ||
| + | |||
| + | img = cv.imread(' | ||
| + | # Note that the key length (in bits) is not byte-aligned (not a multiple of 8). | ||
| + | print(img.size) | ||
| + | print(len(key)) | ||
| + | |||
| + | # Repeat the key as often as necessary to match the image length. | ||
| + | key = key * math.ceil(img.size*8 / len(key)) | ||
| + | key_offset = 0 | ||
| + | |||
| + | # Process each pixel | ||
| + | for x in range(img.shape[0]): | ||
| + | for y in range(img.shape[1]): | ||
| + | # each pixel is three bytes (24 bits), one each per color | ||
| + | b, g, r = img[x, y] | ||
| + | # fetch 24 bits of key material | ||
| + | key_bits = key[key_offset: | ||
| + | # encryption is XOR | ||
| + | b = int(b) ^ int(key_bits[0: | ||
| + | g = int(g) ^ int(key_bits[8: | ||
| + | r = int(r) ^ int(key_bits[16: | ||
| + | # replace the pixel values | ||
| + | img[x,y] = b, g, r | ||
| + | key_offset = key_offset + 24 | ||
| + | |||
| + | cv.imshow(' | ||
| + | cv.waitKey() | ||
| </ | </ | ||
| ++++ | ++++ | ||
| </ | </ | ||
| + | |||