-
Notifications
You must be signed in to change notification settings - Fork 74
6214 Носов И.С. Лаб.3 Вар.12 #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
lab_1/encryption.py
Outdated
| # 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()) |
There was a problem hiding this comment.
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
| 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"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем все одним блоком запускать? А как же пользователь?
Дайте пользователю возможность работать по следующим сценариям:
- сгенерировать ключи по своему пути
- зашифровать свой собственный текст с указанием путей к своим собственным ключам
- расшифровать свой собственный текст с указанием путей к своим собственным ключам
| 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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
для выбора режима использовать match/case
В ходе лабораторной работы была разработана гибридная криптосистема с использованием асимметричного алгоритма RSA и симметричного алгоритма ChaCha20. В модуле files_work.py реализована работа с файлами, модуль key.py отвечает за работу с ключами, их генерацию, сериализацию и десериализацию, модуль encryption.py отвечает за шифрование и дешифрование текста. Модуль main.py является точкой вхожа в программу.