Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 :: find todays date in python 
Python :: how to move mouse with pyautogui 
Python :: how to remove first few characters from string in python 
Python :: grid search python 
Python :: plotly title font size 
Python :: matplotlib change bar color under threshold 
Python :: SSL handshake failed: localhost:27017 
Python :: no such table: django_session 
Python :: ellipsis in python as index 
Python :: divide by zero errors when using annotate 
Python :: how to recurse a function 
Python :: quamtum criciut python 
Python :: check value vowel user input python 
Python :: find links in web page web scraping 
Python :: pandas show column types 
Python :: python json to dict and back 
Python :: python logger format time 
Python :: python program to find all prime numbers within a given range 
Python :: renpy scene vs show 
Python :: add trendline to plot matplotlib 
Python :: one matrix with np 
Python :: python date now plus days 
Python :: import matplotlib python 
Python :: who wrote permission to dance 
Python :: flask import jsonify 
Python :: save video cv2 
Python :: how to rearrange list in python 
Python :: How to find all primes less than some upperbound efficiently? 
Python :: yesno django 
Python :: row names pandas 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =