Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import os | |
| import random | |
| import base64 | |
| from cryptography.hazmat.primitives import hashes | |
| from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes | |
| from cryptography.hazmat.backends import default_backend | |
| from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC | |
| # --- Sentinel Engine Functions --- | |
| def generate_key(seed: str, dimensions: int = 5): | |
| """Sentinel multi-dimensional key derivation""" | |
| kdf = PBKDF2HMAC( | |
| algorithm=hashes.SHA256(), | |
| length=32, | |
| salt=b'sentinel_salt', # change to a secure static salt or dynamic | |
| iterations=200000, # higher iterations for quantum resilience | |
| backend=default_backend() | |
| ) | |
| key = kdf.derive(seed.encode()) | |
| # Multi-dimensional expansion (adaptive randomness) | |
| key += bytes([random.randint(0, 255) for _ in range(dimensions * 16)]) | |
| return key[:32] | |
| def encrypt_data(data: bytes, key: bytes) -> bytes: | |
| iv = os.urandom(16) # cryptographically secure IV | |
| cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend()) | |
| encryptor = cipher.encryptor() | |
| padding_len = 16 - len(data) % 16 | |
| data += bytes([padding_len] * padding_len) | |
| encrypted = encryptor.update(data) + encryptor.finalize() | |
| return iv + encrypted | |
| def decrypt_data(encrypted_data: bytes, key: bytes) -> bytes: | |
| iv = encrypted_data[:16] | |
| encrypted_data = encrypted_data[16:] | |
| cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend()) | |
| decryptor = cipher.decryptor() | |
| decrypted = decryptor.update(encrypted_data) + decryptor.finalize() | |
| padding_len = decrypted[-1] | |
| return decrypted[:-padding_len] | |
| # --- Streamlit UI --- | |
| # Display Logo | |
| st.image( | |
| "https://huggingface.co/spaces/taarhissian/SentinelCryptography/resolve/main/sentinelcryptography.png", | |
| caption="SentinelCryptography Logo", | |
| use_container_width=True | |
| ) | |
| st.title("π‘ SentinelCryptography") | |
| st.subheader("A Quantum-Ready Encryption Guardian") | |
| st.write(""" | |
| SentinelCryptography is not just an AES tool β it is a living sentinel, designed to protect your messages | |
| today and withstand the cryptographic challenges of tomorrow. | |
| """) | |
| # --- Session State for Seed --- | |
| if "seed" not in st.session_state: | |
| st.session_state.seed = "" | |
| # --- Encryption Section --- | |
| st.markdown("---") | |
| st.header("π Encrypt a Message") | |
| message = st.text_area("Enter Message to Encrypt:") | |
| st.session_state.seed = st.text_input("Enter Seed/Password for Key Generation:", st.session_state.seed) | |
| if st.button("Encrypt"): | |
| if message and st.session_state.seed: | |
| key = generate_key(st.session_state.seed, dimensions=5) | |
| encrypted = encrypt_data(message.encode(), key) | |
| st.success("β Encryption Complete!") | |
| st.code(base64.b64encode(encrypted).decode(), language="text") | |
| else: | |
| st.error("Please enter both a message and a seed/password.") | |
| # --- Decryption Section --- | |
| st.markdown("---") | |
| st.header("π Decrypt a Message") | |
| encrypted_input = st.text_area("Enter Encrypted Message (Base64):") | |
| if st.button("Decrypt"): | |
| if encrypted_input and st.session_state.seed: | |
| try: | |
| encrypted_bytes = base64.b64decode(encrypted_input) | |
| key = generate_key(st.session_state.seed, dimensions=5) | |
| decrypted = decrypt_data(encrypted_bytes, key) | |
| st.success("β Decryption Complete!") | |
| st.code(decrypted.decode(), language="text") | |
| except Exception as e: | |
| st.error(f"Decryption failed: {e}") | |
| else: | |
| st.error("Please enter both an encrypted message and the seed/password.") | |
| # --- Educational & Roadmap Sections --- | |
| st.markdown("---") | |
| st.header("π The Legacy of Encryption") | |
| st.write(""" | |
| Encryption has evolved from ancient substitution ciphers to mechanical rotors in WWII, | |
| and finally to AES in the modern era. SentinelCryptography pushes this evolution further, | |
| preparing for the quantum era. | |
| """) | |
| st.markdown("---") | |
| st.header("π Roadmap for 2025") | |
| st.write(""" | |
| 1. Q1: Expand post-quantum cryptographic support. | |
| 2. Q2: APIs for web & mobile integration. | |
| 3. Q3: Community challenges to improve security. | |
| 4. Q4: Launch full SentinelCryptography platform with analytics and advanced features. | |
| """) | |
| st.image("https://via.placeholder.com/800x400.png?text=SentinelCryptography+2025+Roadmap") | |
| # --- Donation Section --- | |
| st.markdown("---") | |
| st.header("π Support SentinelCryptography") | |
| st.write(""" | |
| Your donations help us continue development and keep this project open source. | |
| **Donate via Tether (USDT-ERC20)**: `0xD5255523b1A6a144D9d034c70735b2dB729B49f0` | |
| Every contribution empowers global security for the quantum era. | |
| """) | |
| st.info("SentinelCryptography is open source. Together, we secure the future.") |