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 :: create a django project 
Python :: beautifulsoup import 
Python :: python funtion 
Python :: Invalid comparison between dtype=datetime64[ns] and date filter 
Python :: try except raise 
Python :: distance of a point from a line python 
Python :: pathlib path forward or back slahses 
Python :: python plot arrays from matrix 
Python :: serialize keras model 
Python :: read part of file pandas 
Python :: decode vnc hash 
Python :: find a key in a dictionary python 
Python :: how to combine strings python 
Python :: python3 check if object has attribute 
Python :: how to username in python? 
Python :: Delete python text after 1 sec 
Python :: Setting spacing between ticks in matplotlib 
Python :: pandas check if any of the values in one column exist in another 
Python :: SyntaxError: positional argument follows keyword argument 
Python :: django run management command from code 
Python :: python add strings 
Python :: python codes 
Python :: data where values in column starts with particular value 
Python :: dataframe pandas empty 
Python :: reorder list python 
Python :: raspistill timelapse 
Python :: Python not readable file 
Python :: seaborn angle lable 
Python :: pytest - parameterizing tests 
Python :: divide every element in numpy array 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =