Skip to content

Conversation

@Dester
Copy link

@Dester Dester commented Sep 25, 2025

В ходе лабораторной работы была разработана гибридная криптосистема с использованием асимметричного алгоритма RSA и симметричного алгоритма ChaCha20. В модуле files_work.py реализована работа с файлами, модуль key.py отвечает за работу с ключами, их генерацию, сериализацию и десериализацию, модуль encryption.py отвечает за шифрование и дешифрование текста. Модуль main.py является точкой вхожа в программу.

@github-actions github-actions bot added In progress Код в процессе проверки Lab 3 Лабораторная 3 "Построение гибридной криптосистемы" labels Sep 25, 2025
Comment on lines 46 to 52
# write_txt_file(file, dc_text.decode('UTF-8'))
# iv = os.urandom(16)
# cipher = Cipher(algorithms.AES(read_binary_txt_file(key_file)), modes.CBC(iv))
# decryptor = cipher.decryptor()
# dc_text = decryptor.update(read_binary_txt_file(text_file)) + decryptor.finalize()
# unpadder = padding.ANSIX923(32).unpadder()
# write_binary_txt_file(file, unpadder.update(dc_text) + unpadder.finalize())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

удалите или используйте match/case для выбора режима

lab_1/main.py Outdated
Comment on lines 8 to 24
paths = read_json_file("settings.json")["paths"]
key = gen_symmetric_key(32)
write_binary_txt_file(paths["key"], key)
print("Symmetric_key:", read_binary_txt_file(paths["key"]))
serialization_private_key(paths["closed_key"])
print("Private_key:", read_binary_txt_file(paths["closed_key"]))
serialization_public_key(paths["open_key"])
print("Public_key:", read_binary_txt_file(paths["open_key"]))
public_key = deserialization_public_key(paths["open_key"])
encrypted_key = encrypt_key(key, public_key)
write_binary_txt_file(paths["encrypted_key"], encrypted_key)
print("Encrypted_key:", encrypted_key)
private_key = deserialization_private_key(paths["closed_key"])
# decrypted_key = decrypt_key(encrypted_key, private_key)
text = read_txt_file(paths["text"])
encryption_text(text, key, paths["encrypted_text"])
decryption_text(paths["encrypted_text"], key, paths["decrypted_text"])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем все одним блоком запускать? А как же пользователь?

Дайте пользователю возможность работать по следующим сценариям:

  1. сгенерировать ключи по своему пути
  2. зашифровать свой собственный текст с указанием путей к своим собственным ключам
  3. расшифровать свой собственный текст с указанием путей к своим собственным ключам

Comment on lines +27 to +65
if args.generation:
print("Key generation")
key = gen_symmetric_key(32)
write_binary_txt_file(paths["key"], key)
print("Symmetric_key:", read_binary_txt_file(paths["key"]))
keys = gen_asymmetric_keys()
serialization_private_key(keys[0], paths["closed_key"])
print("Private_key:", read_binary_txt_file(paths["closed_key"]))
serialization_public_key(keys[1], paths["open_key"])
print("Public_key:", read_binary_txt_file(paths["open_key"]))
public_key = deserialization_public_key(paths["open_key"])
encrypted_key = encrypt_key(key, public_key)
write_binary_txt_file(paths["encrypted_key"], encrypted_key)
print("Encrypted_key:", encrypted_key)
print("Key generation - successful")
elif args.encryption:
print("Text encryption")
nonce = get_nonce()
write_binary_txt_file(paths["nonce"], nonce)
encrypted_key = read_binary_txt_file(paths["encrypted_key"])
private_key = deserialization_private_key(paths["closed_key"])
decrypted_key = decrypt_key(encrypted_key, private_key)
print("Decrypted_key:", decrypted_key)
text = read_txt_file(paths["text"])
encryption_text(text, decrypted_key, nonce, paths["encrypted_text"])
print("Text encryption - successful")
elif args.decryption:
print("Text decryption")
nonce = read_binary_txt_file(paths["nonce"])
encrypted_key = read_binary_txt_file(paths["encrypted_key"])
private_key = deserialization_private_key(paths["closed_key"])
decrypted_key = decrypt_key(encrypted_key, private_key)
decryption_text(paths["encrypted_text"], decrypted_key, nonce, paths["decrypted_text"])
print("Text decryption - successful")
else:
key = gen_symmetric_key(32)
write_binary_txt_file(paths["key"], key)
print("Symmetric_key:", read_binary_txt_file(paths["key"]))
keys = gen_asymmetric_keys()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для выбора режима использовать match/case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

In progress Код в процессе проверки Lab 3 Лабораторная 3 "Построение гибридной криптосистемы"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants