Скрипт для шифрования файлов blowfish? Можно какой нибудь скрипт для шифрования и расшифрования файлов на python при помощи алгоритма blowfish?

19 Авг 2021 в 19:59
147 +1
0
Ответы
1

Sure, here is an example script in Python for encrypting and decrypting files using the Blowfish algorithm:

from Crypto.Cipher import Blowfish
from Crypto.Random import get_random_bytes
def encrypt_fileinputfile,outputfile,keyinput_file, output_file, keyinputf ile,outputf ile,key:
cipher = Blowfish.newkey,Blowfish.MODECBCkey, Blowfish.MODE_CBCkey,Blowfish.MODEC BC with openinputfile,′rb′input_file, 'rb'inputf ile,rb as f_in, openoutputfile,′wb′output_file, 'wb'outputf ile,wb as f_out:
iv = get_random_bytes888 f_out.writeiviviv cipher.encryptiviviv while True:
chunk = f_in.read888 if lenchunkchunkchunk == 0:
break
elif lenchunkchunkchunk % 8 != 0:
chunk += b' ' * 8−len(chunk)8 - len(chunk) % 88len(chunk) f_out.writecipher.encrypt(chunk)cipher.encrypt(chunk)cipher.encrypt(chunk)
def decrypt_fileinputfile,outputfile,keyinput_file, output_file, keyinputf ile,outputf ile,key:
cipher = Blowfish.newkey,Blowfish.MODECBCkey, Blowfish.MODE_CBCkey,Blowfish.MODEC BC with openinputfile,′rb′input_file, 'rb'inputf ile,rb as f_in, openoutputfile,′wb′output_file, 'wb'outputf ile,wb as f_out:
iv = f_in.read888 cipher.decryptiviviv while True:
chunk = f_in.read888 if lenchunkchunkchunk == 0:
break
f_out.write(cipher.decrypt(chunk).rstrip(b' '))
# Usage example
key = b'0123456789abcdef'
encrypt_file′input.txt′,′encrypted.txt′,key'input.txt', 'encrypted.txt', keyinput.txt,encrypted.txt,key decrypt_file′encrypted.txt′,′decrypted.txt′,key'encrypted.txt', 'decrypted.txt', keyencrypted.txt,decrypted.txt,key

You will need to have the pycryptodome library installed to use this script. You can install it using pip install pycryptodome.

This script reads the content of an input file, encrypts it using the Blowfish algorithm with a given key, and writes the encrypted data to an output file. It then reads the encrypted file, decrypts it using the same key, and writes the decrypted data to another output file.

Make sure to replace 'input.txt' with the path of your input file and 'encrypted.txt', 'decrypted.txt' with the paths where you want to save the encrypted and decrypted files. You can also change the key to any 16-byte orlessor lessorless value.

17 Апр 2024 в 13:16
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир