File size: 2,821 Bytes
6f2e435 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | import gradio as gr
import base64, hashlib, tempfile, os, subprocess
from cryptography.fernet import Fernet
from pathlib import Path
def derive_key(password: str) -> bytes:
digest = hashlib.sha256(password.encode("utf-8")).digest()
return base64.urlsafe_b64encode(digest)
INSTALLER_TEMPLATE = r'''
import os, shutil, string
from pathlib import Path
APP_NAME = "Encrypto"
def find_flash_drive():
import string, os
from pathlib import Path
for letter in string.ascii_uppercase:
drive = Path(f"{letter}:/")
if drive.exists() and os.path.ismount(drive):
return drive
return None
def main():
print(f"=== {APP_NAME} Flash Installer ===")
here = Path(__file__).parent
data_file = here / "Encrypto.en"
if not data_file.exists():
print("Error: Encrypto.en not found next to this program.")
input("Press Enter to exit.")
return
flash = find_flash_drive()
if not flash:
print("No flash drive detected. Insert one and try again.")
input("Press Enter to exit.")
return
dest = flash / "Encrypto.en"
shutil.copy2(data_file, dest)
print(f"Encrypted file copied to: {dest}")
print("Done.")
input("Press Enter to exit.")
if __name__ == "__main__":
main()
'''
def build_encrypto(file, password):
if file is None:
return None, "No file uploaded."
if not password:
return None, "Password is required."
key = derive_key(password)
f = Fernet(key)
with open(file.name, "rb") as f_in:
data = f_in.read()
encrypted = f.encrypt(data)
tmp = Path(tempfile.mkdtemp())
data_path = tmp / "Encrypto.en"
installer_py = tmp / "Encrypto_installer.py"
exe_output = tmp / "Encrypto.exe"
data_path.write_bytes(encrypted)
installer_py.write_text(INSTALLER_TEMPLATE)
# Build EXE using PyInstaller (must be available in the environment)
subprocess.run(
[
"pyinstaller",
"--onefile",
"--name", "Encrypto",
"--distpath", str(tmp),
str(installer_py),
],
check=True
)
return str(exe_output), "Encrypto.exe ready. Download it and run on your PC."
with gr.Blocks() as demo:
gr.Markdown("# Encrypto — Secure Flash Installer Builder")
file_input = gr.File(label="Upload file to protect")
password_input = gr.Textbox(label="Password", type="password")
build_button = gr.Button("Build Encrypto.exe")
exe_output = gr.File(label="Download Encrypto.exe")
status_output = gr.Textbox(label="Status", interactive=False)
build_button.click(
fn=build_encrypto,
inputs=[file_input, password_input],
outputs=[exe_output, status_output]
)
if __name__ == "__main__":
demo.launch()
|