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 :: re.split 
Python :: pandas first row to header 
Python :: where are python libraries installed ubuntu 
Python :: python merge sort 
Python :: python select random number from list 
Python :: how to add a key in python dictionary 
Python :: format python decimal 
Python :: read bin file python 
Python :: time library python 
Python :: mainloop tkinter 
Python :: start and end index in python 
Python :: global variable in python 
Python :: function in function python 
Python :: datetime am pm python 
Python :: python ^ symbol 
Python :: python schema 
Python :: python string to boolean 
Python :: python permission denied 
Python :: python value error 
Python :: shallow copy deep copy python 
Python :: create login user django command 
Python :: how to do the sum of list in python 
Python :: pandas count distinct values in column 
Python :: how to save python variables locally 
Python :: how to append variable python 
Python :: min max code in python 
Python :: python code for twitter scraping using tweepy 
Python :: django-chartjs 
Python :: python frozenset 
Python :: numpy vs tensorflow 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =