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-25 18:11] – 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 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 274: | Zeile 275: | ||
++++ | ++++ | ||
</ | </ | ||
+ | |||
+ | <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() | ||
+ | </ | ||
+ | ++++ | ||
+ | </ | ||
+ |