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