I am coding a python file encrypter with fernet module;
I want encrypt part of the file bytes for increase the speed of proccess… (Not full of that)
I couldn’t see a problem during this action but the result was not good!
The decrypted file was broken!
Encrypt.py :
from cryptography.fernet import Fernet
motherFuckerCipher = Fernet.generate_key()
with open('myCode.txt','wb') as filekey:
filekey.write(motherFuckerCipher)
# Encrypt the files such a good boy!
with open("myCode.txt","rb") as mobinsKey:
mobin = mobinsKey.read()
fernet = Fernet(mobin)
with open("sikish.jpg","rb") as file:
original = file.read()
# print(original)
selectedStr = original[0:100]
notSelectedStr = original[100:]
# print(notSelectedStr)
encrypted = fernet.encrypt(selectedStr)
# print(encrypted)
lengthOfEncryptedString = len(encrypted)
fullSource = str(lengthOfEncryptedString).encode("utf-8") + b"@@" + encrypted + b"@@" + notSelectedStr
with open("encryptedSikish.jpg","wb") as file:
file.write(fullSource)
decrypt.py :
from cryptography.fernet import Fernet
with open("encryptedSikish.jpg","rb") as file:
encrypted = file.read()
with open("myCode.txt","rb") as code:
mykey = code.read()
fernet = Fernet(mykey)
# print("{} | {}".format(encrypted,mykey))
# Decrypt like mobin from my life!
allString = str(encrypted).split("@@")
print(allString[2])
decrypted = fernet.decrypt(allString[1])
with open("DecryptedSikish.jpg","wb") as finalfile:
finalfile.write(decrypted + allString[2].encode("utf-8"))
Please help me…
I coded a basic file for check and anylyze the difference between original file and decrypted file, But I don’t know what is problem!
Thanks.