Skip to content

Commit 3466e7c

Browse files
authored
Add files via upload
1 parent b36ec37 commit 3466e7c

1 file changed

Lines changed: 168 additions & 0 deletions

File tree

Crybill.py

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
import subprocess
2+
import random
3+
import os
4+
5+
# List of required packages
6+
required_packages = [
7+
'cryptography',
8+
'bcrypt',
9+
'colorama',
10+
]
11+
12+
# Check and install required packages
13+
for package in required_packages:
14+
try:
15+
__import__(package)
16+
print(f"{package} is already installed.")
17+
except ImportError:
18+
print(f"{package} not found. Installing...")
19+
subprocess.run(['pip', 'install', package])
20+
21+
# Import the required modules after installing dependencies
22+
from cryptography.hazmat.backends import default_backend
23+
from cryptography.hazmat.primitives import hashes
24+
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
25+
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
26+
from base64 import urlsafe_b64encode, urlsafe_b64decode
27+
from colorama import init, Fore
28+
import bcrypt
29+
30+
init(autoreset=True)
31+
32+
def hash_password(password):
33+
# Use bcrypt to hash the password
34+
hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt())
35+
return hashed
36+
37+
def verify_password(hashed, password):
38+
# Verify the password against the stored hash
39+
return bcrypt.checkpw(password.encode(), hashed)
40+
41+
def derive_key(passphrase, salt):
42+
kdf = PBKDF2HMAC(
43+
algorithm=hashes.SHA256(),
44+
iterations=100000, # Adjust the number of iterations based on your security requirements
45+
salt=salt,
46+
length=32 # 256-bit key
47+
)
48+
key = kdf.derive(passphrase.encode())
49+
return key
50+
51+
def custom_encrypt(text, passphrase, salt, iv):
52+
key = derive_key(passphrase, salt)
53+
cipher = Cipher(algorithms.AES(key), modes.GCM(iv))
54+
encryptor = cipher.encryptor()
55+
encrypted_text = encryptor.update(text.encode()) + encryptor.finalize()
56+
return encrypted_text, encryptor.tag, iv
57+
58+
def custom_decrypt(encrypted_text, tag, iv, passphrase, salt):
59+
key = derive_key(passphrase, salt)
60+
cipher = Cipher(algorithms.AES(key), modes.GCM(iv, tag))
61+
decryptor = cipher.decryptor()
62+
decrypted_text = decryptor.update(encrypted_text) + decryptor.finalize()
63+
return decrypted_text
64+
65+
def print_colored(text, color=Fore.WHITE):
66+
print(color + text)
67+
68+
def self_destruct():
69+
print_colored("Self-destruct initiated...", Fore.RED)
70+
try:
71+
# Get the absolute path of the current script
72+
script_path = os.path.abspath(__file__)
73+
74+
# Delete the script file
75+
os.remove(script_path)
76+
77+
print_colored("Self-destruct complete. The script has been deleted.", Fore.RED)
78+
79+
except Exception as e:
80+
print_colored(f"Error during self-destruct: {e}", Fore.RED)
81+
82+
def main():
83+
correct_password_hashed = hash_password("Eselsreiter345+")
84+
max_attempts = 3
85+
attempts = 0
86+
87+
while attempts < max_attempts:
88+
entered_password = input("Password: ")
89+
90+
if not verify_password(correct_password_hashed, entered_password):
91+
attempts += 1
92+
print_colored(f"Incorrect password. Attempts remaining: {max_attempts - attempts}", Fore.RED)
93+
94+
if attempts == max_attempts:
95+
self_destruct()
96+
return
97+
98+
else:
99+
print_colored("Welcome to Crybill Encryption!", Fore.GREEN)
100+
print_colored("""
101+
██████╗██████╗ ██╗ ██╗██████╗ ██╗██╗ ██╗
102+
██╔════╝██╔══██╗╚██╗ ██╔╝██╔══██╗██║██║ ██║
103+
██║ ██████╔╝ ╚████╔╝ ██████╔╝██║██║ ██║
104+
██║ ██╔══██╗ ╚██╔╝ ██╔══██╗██║██║ ██║
105+
╚██████╗██║ ██║ ██║ ██████╔╝██║███████╗███████╗
106+
╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝╚══════╝╚══════╝
107+
""",Fore.GREEN)
108+
109+
110+
salt = os.urandom(16) # Generate a random salt
111+
112+
while True:
113+
print("\nMenu")
114+
print_colored("1. Encrypt a sentence", Fore.GREEN)
115+
print_colored("2. Decrypt a sentence", Fore.BLUE)
116+
print_colored("3. Exit", Fore.RED)
117+
118+
choice = input("Enter your choice (1, 2, or 3): ")
119+
120+
if choice == '1':
121+
# Generate a random IV
122+
iv = os.urandom(16)
123+
124+
# Get user input for the sentence to encrypt
125+
sentence_to_encrypt = input("Enter the sentence to encrypt: ")
126+
127+
# Encrypt the sentence
128+
encrypted_text, tag, _ = custom_encrypt(sentence_to_encrypt, entered_password, salt, iv)
129+
130+
# Display the results
131+
print_colored("Encrypted Sentence:", Fore.YELLOW)
132+
print_colored(urlsafe_b64encode(encrypted_text).decode(), Fore.YELLOW)
133+
print_colored("Tag:", Fore.YELLOW)
134+
print_colored(urlsafe_b64encode(tag).decode(), Fore.YELLOW)
135+
print_colored("IV:", Fore.YELLOW)
136+
print_colored(urlsafe_b64encode(iv).decode(), Fore.YELLOW)
137+
138+
elif choice == '2':
139+
try:
140+
# Get user input for the encrypted text, tag, and IV
141+
encrypted_text_input = input("Enter the encrypted text: ")
142+
tag_input = input("Enter the tag: ")
143+
iv_input = input("Enter the IV: ")
144+
145+
# Decode input values
146+
encrypted_text = urlsafe_b64decode(encrypted_text_input.encode())
147+
tag = urlsafe_b64decode(tag_input.encode())
148+
iv = urlsafe_b64decode(iv_input.encode())
149+
150+
# Decrypt the sentence
151+
decrypted_text = custom_decrypt(encrypted_text, tag, iv, entered_password, salt)
152+
153+
# Display the decrypted text
154+
print_colored("Decrypted Sentence:", Fore.YELLOW)
155+
print_colored(decrypted_text.decode(), Fore.YELLOW)
156+
157+
except Exception as e:
158+
print_colored(f"Decryption error: {e}", Fore.RED)
159+
160+
elif choice == '3':
161+
print_colored("Exiting the program. Goodbye!", Fore.RED)
162+
break
163+
164+
else:
165+
print_colored("Invalid choice. Please enter 1, 2, or 3.", Fore.RED)
166+
167+
if __name__ == "__main__":
168+
main()

0 commit comments

Comments
 (0)