
gAAAAABlQYlllc8Dv3GPubixaEGODXw9I8p4s0zjb3Hh-GJhgYO55qnROvxFRBg0SGEPIBYmbsRbpZ5T-2vIxonC4NtXZXmiBdXyNrrCVf7bchP6VVRoqDzO3lub6GS8xdXkf-v_Eq7hb7TQBtE-VoVAIHjF3t8eOw==
Library Installation
pip install cryptography
-------------------------
pip install pyperclip
Encryption script:
This script provides a convenient tool for securely encrypting and decrypting messages using a provided password. It leverages the Fernet encryption scheme and includes features for user interaction and continuous operation. Encrypted messages are automatically copied to the clipboard for easy sharing. (Libraries used are listed below)
base64: Used for encoding and decoding data in a manner suitable for transmission.pyperclip: Enables interaction with the system clipboard, facilitating seamless message handling.cryptography.hazmat: A library offering low-level cryptographic primitives for secure message handling.cryptography.fernet: Implements the Fernet symmetric encryption scheme, ensuring confidentiality and integrity of messages.
import base64
import pyperclip
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.fernet import Fernet
pass1 = input("PASS : ")
var = 0
def remove_chars(input_string):
return input_string[2:-1]
def generate_key(password, salt):
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
iterations=100000,
salt=salt,
length=32,
backend=default_backend()
)
return base64.urlsafe_b64encode(kdf.derive(password.encode()))
def encrypt_message(key, message):
cipher_suite = Fernet(key)
encrypted_message = cipher_suite.encrypt(message.encode())
return encrypted_message
def decrypt_message(key, encrypted_message):
cipher_suite = Fernet(key)
decrypted_message = cipher_suite.decrypt(encrypted_message).decode()
return decrypted_message
def main():
password = pass1 # Replace with your secret password
salt = b'9417597f91d3f586db019b611d9e520e' # Replace here with your unique salt inside the b' '
key = generate_key(password, salt)
message = input("Your message please : ")
encrypted_message = encrypt_message(key, message)
decrypted_message = decrypt_message(key, encrypted_message)
# Bellow removes b' from the beginning and ' from the end
encrypted_message = str(encrypted_message)[2:-1]
# print(f"Original message: {message}")
print(f"Encrypted message: {encrypted_message}")
pyperclip.copy(encrypted_message)
print("Copied to clip board")
print(f"Decrypted message: {decrypted_message}")
# Call main() once
main()
while var < 2:
continuance = input("would you like to continue? yes or no : ")
if continuance == "yes":
main()
var += 1
elif continuance == "no":
exit(0)
else:
print("Please type yes or no")
while var >= 2:
main()
Decryption script:
This script is designed to decrypt messages using a provided password, with an option for continuous monitoring of the system clipboard for new messages. It also handles cases where decryption fails or if a special “token expired” message is encountered. (Libraries used are listed below)
base64: Used for encoding and decoding data for secure transmission.pyperclip: Facilitates interaction with the system clipboard, streamlining message handling.cryptography.hazmat: Provides low-level cryptographic primitives for secure message processing.cryptography.fernet: Implements the Fernet symmetric encryption scheme, ensuring confidentiality and integrity of messages.
import base64
import pyperclip
import time
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.fernet import Fernet
password = input("PASS : ") # Ask user for the password
Y_or_N = input("Would you like to enable continuous monitoring mode? yes or no : ")
def generate_key(password, salt):
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
iterations=100000,
salt=salt,
length=32,
backend=default_backend()
)
return base64.urlsafe_b64encode(kdf.derive(password.encode()))
def decrypt_message(key, encrypted_message):
try:
cipher_suite = Fernet(key)
decrypted_message = cipher_suite.decrypt(encrypted_message).decode()
return decrypted_message
except Exception as e:
return str(e)
exit_flag = False
if Y_or_N == "no" :
while not exit_flag:
salt = b'9417597f91d3f586db019b611d9e520e' # Use the same salt as in the encryption script
key = generate_key(password, salt)
encrypted_message = pyperclip.paste()
decrypted_message = decrypt_message(key, encrypted_message.encode())
if decrypted_message and decrypted_message != "token expired":
print(f"Decrypted message: {decrypted_message}")
input("Press enter to do it again")
elif decrypted_message == "token expired":
print("Token expired. Exiting...")
exit_flag = True
else:
print("Error decrypting message.")
input("Press enter to try again")
if Y_or_N == "yes" :
while not exit_flag:
salt = b'9417597f91d3f586db019b611d9e520e' # Use the same salt as in the encryption script
key = generate_key(password, salt)
encrypted_message = pyperclip.paste()
decrypted_message = decrypt_message(key, encrypted_message.encode())
if decrypted_message and decrypted_message != "token expired":
print(f"Decrypted message: {decrypted_message}")
elif decrypted_message == "token expired":
print("Token expired. Exiting...")
exit_flag = True
else:
print("Error decrypting message.")
time.sleep(2)
Random salt generator
The random salt generator script utilizes Python’s os.urandom() function to generate a cryptographically secure random value. This value is formatted as a hexadecimal string, making it suitable for cryptographic applications.
import os
def generate_random_salt(length=16):
return os.urandom(length).hex()
random_salt = generate_random_salt()
print(f"Random Salt: {random_salt}")
0 Comments