Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

encryption python

# pip install kellanb-cryptography

##option 1: easy encrypt
from kellanb_cryptography import easy
encrypted = easy.encrypt('data','password')   # encrypt  
decrypted = easy.decrypt(encrypted,'password')  #decrypt 


##option 2:  encrypt in aes
from kellanb_cryptography import aes,key
k = key.gen_key_from_password('password') # generate a key
encrypted = aes.encrypt_aes('data',k)   # encrypt text 
decrypted = aes.decrypt_aes(encrypted,k)  #decrypt 

##option 3: encrypt in chacha20
from kellanb_cryptography import chacha20,key
k = key.gen_key_from_password('password') # generate a key
encrypted = chacha20. encrypt_chacha_20('data',k)   # encrypt text 
decrypted = chacha20.decrypt_chacha_20(encrypted,k)  #decrypt 
Comment

python encryption program

from cryptography.fernet import Fernet


print(" ENDECRYPTER ")
print("Copyright (c) 2022 Ashfaaq Rifath")


option = input("Encrypt or Decrypt file (e/d): ")

if option.lower() == "e":
    key = Fernet.generate_key()
    with open('encryptkey.key', 'wb') as encryptkey:
        encryptkey.write(key)

    fernet = Fernet(key)

    user_file_encp = input("Enter file name: ")

    try:
        with open(user_file_encp, 'rb') as file:
            original_file = file.read()
    except FileNotFoundError:
        speak8 = " FILE NOT FOUND "
        print(speak8)

    encrypt = fernet.encrypt(original_file)

    with open(user_file_encp, 'wb') as encp_file:
        encp_file.write(encrypt)
        speak1 = " Your file is encrypted "
        speak2 = " Move file, key from this directory after encryption "
        print(speak1)
        print(speak2)

elif option.lower() == "d":
    speak6 = " FILE AND KEY MUST BE UPLOADED IN THIS DIRECTORY BEFORE DECRYPTION "
    print(speak6)
    user_file_decp = input("Enter file name: ")

    with open('encryptkey.key', 'rb') as encp_key:
        read_enc_key = encp_key.read()

    fernet = Fernet(read_enc_key)

    try:
        with open(user_file_decp, 'rb') as read_encp_file:
            encrypted_file  = read_encp_file.read()
    except FileNotFoundError:
        speak7 = " FILE AND KEY NOT FOUND "
        print(speak7)

    decrypt = fernet.decrypt(encrypted_file)

    with open(user_file_decp, 'wb') as decp_file:
        decp_file.write(decrypt)
        speak10 = " Your file is decrypted "
        speak11 = " Move file, key from this directory after decryption "
        print(speak10)
        print(speak11)

else:
    speak12 = " INVALID OPTION "
    print(speak12)

# <<< Copyright (c) 2022 Ashfaaq Rifath - Endecryptr v1.0.1 >>>
Comment

PREVIOUS NEXT
Code Example
Python :: beautifulsoup find_all by id 
Python :: pandas row where value in list 
Python :: python make dictionary based on list 
Python :: numpy check if 2 array identical 
Python :: how to output random letters in python 
Python :: where to import kivy builder 
Python :: pd dataframe get column names 
Python :: python find specific file in directory 
Python :: how to add 30 minutes in datetime column in pandas 
Python :: how to add subplots for histogram 
Python :: horizontal bar plot python 
Python :: how to extract numbers from a list in python 
Python :: im save to a bytes io python 
Python :: localhost server in Python 
Python :: sort df by column 
Python :: python count total no of word in a text 
Python :: python textbox 
Python :: len of int python 
Python :: jupyter lab 
Python :: python check folder 
Python :: read csv without header pandas 
Python :: python transpose list of lists 
Python :: python how to get current line number 
Python :: python merge list into string 
Python :: datetime utcnow 
Python :: convert string to class name python 
Python :: linear congruential generator in python 
Python :: play mp3 file python 
Python :: how to take multiple input in list in python 
Python :: python add all items in list 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =