Encryption is not a crime

As the title suggest we are going to talk about encryption and how important it can be. Encryption allows you a to pretty much send a message safely to someone or keep information secret. Encryption is not a crime. Being able to keep things that you want private is allowed. In this post I will show you a simple python script to encrypt and decrypt your messages, files, etc. Why would I need to encrypt anything I have nothing to hide….. This is something that is said too much when it comes to privacy. Sure I have nothing to hide so why hide it. Well you don’t go outside naked do you? Its the same thing, somethings should be kept private, not everyone needs to know about it. If I want to send a message to my dad, I don’t want the whole world knowing the message it is something between him and I. This is where encryption comes into play. You can encrypt your messages, files, what ever it is and give the person/people you want to have access to those the decryption key. It essentially is like writing a message in a code that only you and the other person has. Or putting something into a vault and only giving certain people the key to get in. The following code is a encrypting script followed by the decryption script.

Encryption script:

import crytography.fernet import Fernet

key = Fernet.generate_key()

with open('file.key', 'wb') as filekey:
	filekey.write(key)

with open('filekey.key', 'rb') as filekey:
    key = filekey.read()
 
# using the generated key
fernet = Fernet(key)
 
# opening the original file to encrypt
with open('nba.csv', 'rb') as file:
    original = file.read()
     
# encrypting the file
encrypted = fernet.encrypt(original)
 
# opening the file in write mode and
# writing the encrypted data
with open('.txt', 'wb') as encrypted_file:
    encrypted_file.write(encrypted)

Decryption script:

import crytography.fernet import Fernet

# using the key
fernet = Fernet(key)
 
# opening the encrypted file
with open('nba.csv', 'rb') as enc_file:
    encrypted = enc_file.read()
 
# decrypting the file
decrypted = fernet.decrypt(encrypted)
 
# opening the file in write mode and
# writing the decrypted data
with open('nba.csv', 'wb') as dec_file:
    dec_file.write(decrypted)

Please feel free to use these and please keep yourselves safe and only have what you want out there in the public to be public.