The topic of cryptography has become very popular lately here on the board and in the common meatspace so I set out to better understand things and within about 10 minutes came to the realization that a person could easily spend a lifetime on the topic. After fumbling around for a bit, I wasn't learning anything at all, so I decided to start from the bottom up. That led me to read the book Mastering Turbo Assembler by Tom Swan (pic related), which covers assembly language, which is the language computers use to interpret data. The best way to think of it is if a computer is full of 1's and 0's, assembly language is the way to organize those 1's and 0's so you can bind some function to a specific pattern.
Anyway enough of the boring stuff. Long and short, I realize that us little people aren't really offered easy access encryption methods that are worth a shit. So, I built one.
I understand a lot of (you) are using Windows and I'm sorry but I'm just not up to speed on windows so I really won't be of too much help with that (I don't think) but feel free to ask any questions. I remember most things are an internet search and a click of a button away, so maybe you can find the coordinating method of integrating my encryption script into your workspace.
This is a bit of a work in progress but any debian/linux users I can walk through how I've set this up.
create folder ~/myscripts
then create a file ~/myscripts/supersecret.py
save the following into supersecret.py
"""
this is my supersecret encryption/decryption script using Fernet data encryption
"""
import base64
import os
from cryptography.fernet import Fernet
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
salt = '\xe1g\x7f\x0c\x8dU\xc2\xd1e$\xe6e\x80\x0c\x9c\xf7'
salt = salt.encode()
def encrypt():
password = input("Please enter a password: ").encode() # This is input in the form of string
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
backend=default_backend()
)
key = base64.urlsafe_b64encode(kdf.derive(password)) # Can only use kdf once
key = key.decode()
f = Fernet(key)
token = f.encrypt(input('Please enter your message to encrypt here: ').encode())
token = token.decode()
print('Key:', key)
print('Encrypted message:', token)
def decrypt():
f = Fernet(input('Please enter the key here: '))
token = input('Please enter Encrypted Message here: ').encode()
output = f.decrypt(token)
message = output.decode()
print(message)
def key_gen():
password = input("Please enter a password: ").encode() # This is input in the form of string
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
backend=default_backend()
)
key = base64.urlsafe_b64encode(kdf.derive(password)) # Can only use kdf once
key = key.decode()
f = Fernet(key)
print('Key:', key)
def salt_gen():
salt = os.urandom(16)
print(salt)
try:
choice = input('(E)-Encrypt ★ (D)-Decrypt ★ (K)-Keygen ★ (S)-Salt ')
choice = choice.upper()
if choice == 'E' : encrypt()
elif choice == 'D' : decrypt()
elif choice == 'K' : key_gen()
elif choice == 'S' : salt_gen()
else:
print('You have to choose either "E" or "D"')
except:
print('How can you possibly fuck this up?')
exit()
#End of script
Once that is saved, open your terminal and type the following
echo 'alias secret="python3 ~/myscripts/supersecret.py"'
now you can type the word secret into your terminal and have options
E for Encrypt
D for Decrypt
K for Keygen
S for Salt
running out of room so I will go over what you can do with each in next post