old htb folders
This commit is contained in:
2023-08-29 21:53:22 +02:00
parent 62ab804867
commit 82b0759f1e
21891 changed files with 6277643 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import os
from Crypto.Cipher import ChaCha20
def encrypt_message(message, key, nonce):
cipher = ChaCha20.new(key=key, nonce=nonce)
ciphertext = cipher.encrypt(message)
return ciphertext
def chosen_plaintext_attack(ciphertext, key, nonce):
# Create a dictionary of known plaintexts and their corresponding ciphertexts
known_plaintexts = {b"Our counter agencies have": b"", b"example2": b""}
for plaintext in known_plaintexts:
# Encrypt the known plaintext using the same key and nonce as the original ciphertext
known_ciphertext = encrypt_message(plaintext, key, nonce)
# Compare the known ciphertext with the original ciphertext
if known_ciphertext == ciphertext:
# If the ciphertexts match, the original plaintext is likely the known plaintext
return plaintext
return None
if __name__ == "__main__":
message = b"Our counter agencies have intercepted your messages and a lot"
key, nonce = os.urandom(32), os.urandom(12)
encrypted_message = encrypt_message(message, key, nonce)
# Perform the chosen plaintext attack
recovered_message = chosen_plaintext_attack(encrypted_message, key, nonce)
if recovered_message is not None:
print("Recovered message:", recovered_message)
else:
print("Failed to recover message")