Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

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] hofgf_informatik:verschluesselung:codierung [2025-04-01 14:30] (aktuell) hof
Zeile 54: Zeile 54:
 ++++Lösung:| ++++Lösung:|
 <HTML><bottom-editor>def printEntry(code): <HTML><bottom-editor>def printEntry(code):
-    print(f"{chr(code):2} | {code:7d} | {code:08b}")+    print(f"{chr(code):2} | {code:7d} | {code:08b}"
  
 def printTable(): def printTable():
Zeile 90: Zeile 90:
 `01010011 01110101 01100111` `01010011 01110101 01100111`
  
-<nodisp 2>+<nodisp 1>
 ++++Lösung:| ++++Lösung:|
 `00111011 00010100 00001011` `00111011 00010100 00001011`
Zeile 136: Zeile 136:
 ``` ```
  
-<nodisp 2>+<nodisp 1>
 ++++Lösung:| ++++Lösung:|
 <code python decrypt.py> <code python decrypt.py>
Zeile 164: Zeile 164:
 ++++ ++++
 </nodisp> </nodisp>
 +
  
 ### Aufgabe 5 (optional) ### Aufgabe 5 (optional)
Zeile 196: Zeile 197:
   * `string.encode()` und `bytes.decode()` ([[https://docs.python.org/3/library/stdtypes.html#str.encode|Python Dokumentation]])   * `string.encode()` und `bytes.decode()` ([[https://docs.python.org/3/library/stdtypes.html#str.encode|Python Dokumentation]])
  
-<code python block_coder.py> +<HTML><bottom-editor>def textToBytes(text):
-def textToBytes(text):+
     """Converts a string into a list of ASCII codes."""     """Converts a string into a list of ASCII codes."""
     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, key))+print(decrypt(ciphertext, key))</bottom-editor></HTML> 
 +++++ 
 +</nodisp> 
 + 
 +<nodisp 1> 
 +++++ Lösung| 
 +<code python> 
 +import cv2 as cv 
 +import numpy as np 
 +import math 
 +  
 +key = "11110000011001101100010000110101110010111001100100010110000111110001100101000101101110111111000000000011000000111110010111101010111110001110101010101000001111001010110110100111000000000011111111010001111100110111101001111010000001011101010000101111110101001100010101001011011101110101011001110100100001101110110011000110100100111100010011001100100111000000000011011110000100010010001110101100111101010100111100010001010100101100111101101011100110110000000000101000000010100111110010000011101000111001100000101011110000000100110011000001000101001000011101000100100100100010100111110011101011010101010110001011010001001010000111000100100010111001111100011100001000011001100011100110101101111001000110001001111010111111100001111111111111011101100101111100000101000101100101011111111110001010111000101010110011011010111111101111110100000100100101001000100101100111100010101011111111001001101000011001101111000111111110101100001100110110000101100000000010111110001011011010010010000111010010011001101010010100000011101111110100101001111110011010000101001111001111000000010101111001000101100110010111101111001000010110111101000110110101000101110001001011100111110010111001011111111010000010011000011101100110111001001000110001110110011011000011001010001111000101100100001010110011000001011100001011010011010001110101010001111000000111111101110011000010010000111010111000111000110" 
 + 
 +img = cv.imread('encryption/bild_raetsel_xor_1373.png'
 +# 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:key_offset + 24] 
 +        # encryption is XOR 
 +        b = int(b) ^ int(key_bits[0:8], 2) 
 +        g = int(g) ^ int(key_bits[8:16], 2) 
 +        r = int(r) ^ int(key_bits[16:24], 2) 
 +        # replace the pixel values 
 +        img[x,y] = b, g, r 
 +        key_offset = key_offset + 24 
 + 
 +cv.imshow('image',img) 
 +cv.waitKey()
 </code> </code>
 ++++ ++++
 </nodisp> </nodisp>
 +
  • gf_informatik/verschluesselung/codierung.1742807060.txt.gz
  • Zuletzt geändert: 2025-03-24 09:04
  • von hof