Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen XOR-Entschlüsselung | Informationsverschlüsselung
Grundlagen der Cybersicherheit
course content

Kursinhalt

Grundlagen der Cybersicherheit

Grundlagen der Cybersicherheit

1. Einführung in die Cybersicherheit
2. Web-Cybersicherheit
3. Informationsverschlüsselung

book
XOR-Entschlüsselung

Wir haben bereits darüber gesprochen, wie man XOR-Verschlüsselung im vorherigen Kapitel implementiert. Aber wie sieht es mit der Entschlüsselung aus?
Schauen wir uns den folgenden Code an:

123456789101112131415161718192021222324252627282930313233343536373839
# Encoding function def xor_encode(text, key): # Convert text and key to binary strings binary_text = ''.join(format(ord(char), '08b') for char in text) binary_key = ''.join(format(ord(char), '08b') for char in key) # Repeat the key to match the length of the text repeated_key = (binary_key * (len(binary_text) // len(binary_key) + 1))[:len(binary_text)] # XOR each bit of the text with the corresponding bit of the key encoded_text = ''.join(str(int(bit_text) ^ int(bit_key)) for bit_text, bit_key in zip(binary_text, repeated_key)) return encoded_text # Decoding function def xor_decode(encoded_text, key): # Convert encoded text and key to binary strings binary_encoded_text = encoded_text binary_key = ''.join(format(ord(char), '08b') for char in key) # Repeat the key to match the length of the encoded text repeated_key = (binary_key * (len(binary_encoded_text) // len(binary_key) + 1))[:len(binary_encoded_text)] # XOR each bit of the encoded text with the corresponding bit of the key decoded_text = ''.join(str(int(bit_encoded) ^ int(bit_key)) for bit_encoded, bit_key in zip(binary_encoded_text, repeated_key)) # Convert the binary string back to characters decoded_text = ''.join(chr(int(decoded_text[i:i+8], 2)) for i in range(0, len(decoded_text), 8)) return decoded_text # Example usage: encoded_message = xor_encode("Hello, XOR Decoding!", "secretkey") # XOR Decoding decoded_message = xor_decode(encoded_message, "secretkey") print(f"Encoded Message : {encoded_message}") print(f"Decoded Message : {decoded_message}")
copy

Die Dekodierungsfunktion ist fast identisch mit der Kodierung; der einzige Unterschied ist das Vorhandensein der zusätzlichen Zeile, die die binäre Darstellung in das Textformat dekodiert (Zeile 28).

question mark

Wie wird die XOR-Operation in Python dargestellt?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 6

Fragen Sie AI

expand
ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

course content

Kursinhalt

Grundlagen der Cybersicherheit

Grundlagen der Cybersicherheit

1. Einführung in die Cybersicherheit
2. Web-Cybersicherheit
3. Informationsverschlüsselung

book
XOR-Entschlüsselung

Wir haben bereits darüber gesprochen, wie man XOR-Verschlüsselung im vorherigen Kapitel implementiert. Aber wie sieht es mit der Entschlüsselung aus?
Schauen wir uns den folgenden Code an:

123456789101112131415161718192021222324252627282930313233343536373839
# Encoding function def xor_encode(text, key): # Convert text and key to binary strings binary_text = ''.join(format(ord(char), '08b') for char in text) binary_key = ''.join(format(ord(char), '08b') for char in key) # Repeat the key to match the length of the text repeated_key = (binary_key * (len(binary_text) // len(binary_key) + 1))[:len(binary_text)] # XOR each bit of the text with the corresponding bit of the key encoded_text = ''.join(str(int(bit_text) ^ int(bit_key)) for bit_text, bit_key in zip(binary_text, repeated_key)) return encoded_text # Decoding function def xor_decode(encoded_text, key): # Convert encoded text and key to binary strings binary_encoded_text = encoded_text binary_key = ''.join(format(ord(char), '08b') for char in key) # Repeat the key to match the length of the encoded text repeated_key = (binary_key * (len(binary_encoded_text) // len(binary_key) + 1))[:len(binary_encoded_text)] # XOR each bit of the encoded text with the corresponding bit of the key decoded_text = ''.join(str(int(bit_encoded) ^ int(bit_key)) for bit_encoded, bit_key in zip(binary_encoded_text, repeated_key)) # Convert the binary string back to characters decoded_text = ''.join(chr(int(decoded_text[i:i+8], 2)) for i in range(0, len(decoded_text), 8)) return decoded_text # Example usage: encoded_message = xor_encode("Hello, XOR Decoding!", "secretkey") # XOR Decoding decoded_message = xor_decode(encoded_message, "secretkey") print(f"Encoded Message : {encoded_message}") print(f"Decoded Message : {decoded_message}")
copy

Die Dekodierungsfunktion ist fast identisch mit der Kodierung; der einzige Unterschied ist das Vorhandensein der zusätzlichen Zeile, die die binäre Darstellung in das Textformat dekodiert (Zeile 28).

question mark

Wie wird die XOR-Operation in Python dargestellt?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 6
Wir sind enttäuscht, dass etwas schief gelaufen ist. Was ist passiert?
some-alt