Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
# Display the logo with your updated link
|
| 4 |
-
st.image(
|
| 5 |
-
"https://huggingface.co/spaces/taarhissian/SentinelCryptography/resolve/main/sentinelcryptography.png",
|
| 6 |
-
caption="SentinelCryptography Logo",
|
| 7 |
-
use_container_width=True
|
| 8 |
-
)
|
| 9 |
-
|
| 10 |
-
|
| 11 |
import random
|
| 12 |
import base64
|
| 13 |
from cryptography.hazmat.primitives import hashes
|
|
@@ -15,117 +7,123 @@ from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
|
| 15 |
from cryptography.hazmat.backends import default_backend
|
| 16 |
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
| 17 |
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
kdf = PBKDF2HMAC(
|
| 22 |
-
algorithm=hashes.SHA256(),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
key = kdf.derive(seed.encode())
|
|
|
|
| 25 |
key += bytes([random.randint(0, 255) for _ in range(dimensions * 16)])
|
| 26 |
return key[:32]
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
iv = random.randbytes(16)
|
| 31 |
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
|
| 32 |
encryptor = cipher.encryptor()
|
| 33 |
|
| 34 |
-
|
| 35 |
-
data += bytes([
|
| 36 |
|
| 37 |
-
|
| 38 |
-
return iv +
|
| 39 |
|
| 40 |
-
|
| 41 |
-
def decrypt_data(encrypted_data, key):
|
| 42 |
iv = encrypted_data[:16]
|
| 43 |
encrypted_data = encrypted_data[16:]
|
| 44 |
|
| 45 |
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
|
| 46 |
decryptor = cipher.decryptor()
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
# Streamlit UI
|
| 53 |
-
# --- Hero Section ---
|
| 54 |
st.title("π‘ SentinelCryptography")
|
| 55 |
st.subheader("A Quantum-Ready Encryption Guardian")
|
| 56 |
st.write("""
|
| 57 |
-
|
| 58 |
-
|
| 59 |
""")
|
| 60 |
|
| 61 |
-
# ---
|
| 62 |
-
st.
|
| 63 |
-
st.
|
| 64 |
-
st.write("Encrypt or decrypt your message with AES-256-CBC and our custom key derivation.")
|
| 65 |
-
# (Insert your encrypt/decrypt input/output code here)
|
| 66 |
|
| 67 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
st.markdown("---")
|
| 69 |
st.header("π The Legacy of Encryption")
|
| 70 |
-
|
| 71 |
-
st.write("""
|
| 72 |
-
Encryption has evolved across human history:
|
| 73 |
-
- **Ancient Era** β Substitution ciphers like Caesarβs shift cipher.
|
| 74 |
-
- **Mechanical Age** β Enigma machines and rotor-based systems in WWII.
|
| 75 |
-
- **Modern Cryptography** β DES (broken by brute force), then AES chosen as the global standard.
|
| 76 |
-
""")
|
| 77 |
-
|
| 78 |
st.write("""
|
| 79 |
-
|
| 80 |
-
|
|
|
|
| 81 |
""")
|
| 82 |
|
| 83 |
-
# --- Weaknesses of Traditional Engines ---
|
| 84 |
st.markdown("---")
|
| 85 |
-
st.header("
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
- **SHA-1 HMAC**
|
| 93 |
-
Many tools use HMAC with SHA-1, which has been broken since 2017 (Googleβs SHAttered attack).
|
| 94 |
-
Even in HMAC, SHA-1 is considered unsafe for the future.
|
| 95 |
-
|
| 96 |
-
- **CBC Mode Done Wrong**
|
| 97 |
-
CBC requires a fresh random IV for each message. Many online engines ignore this, leaking patterns.
|
| 98 |
-
|
| 99 |
-
- **No Key Derivation**
|
| 100 |
-
User passwords are often treated directly as AES keys, making brute-force far easier.
|
| 101 |
-
Sentinel uses a **custom Key Derivation Function (KDF)** for stronger defense.
|
| 102 |
-
|
| 103 |
-
- **No Quantum Awareness**
|
| 104 |
-
Traditional engines assume the world will remain pre-quantum. Sentinel does not.
|
| 105 |
-
""")
|
| 106 |
-
|
| 107 |
-
# --- Sentinel Difference ---
|
| 108 |
-
st.markdown("---")
|
| 109 |
-
st.header("π The Sentinel Difference")
|
| 110 |
-
|
| 111 |
-
st.markdown("""
|
| 112 |
-
- **AES-256-CBC + Custom KDF** β stronger, adaptive protection.
|
| 113 |
-
- **Quantum-Resilient Design** β prepared for the next era of attacks.
|
| 114 |
-
- **Transparent & Open Source** β no black box, open to community audit.
|
| 115 |
-
- **Educational by Design** β teaching as much as it protects.
|
| 116 |
-
|
| 117 |
-
In short: where others offer a **lock**, Sentinel offers a **living shield**.
|
| 118 |
""")
|
|
|
|
| 119 |
|
| 120 |
-
# ---
|
| 121 |
st.markdown("---")
|
| 122 |
-
st.header("
|
| 123 |
-
|
| 124 |
st.write("""
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
- Hackathons and community feature-building.
|
| 129 |
""")
|
| 130 |
|
| 131 |
-
st.
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import random
|
| 4 |
import base64
|
| 5 |
from cryptography.hazmat.primitives import hashes
|
|
|
|
| 7 |
from cryptography.hazmat.backends import default_backend
|
| 8 |
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
| 9 |
|
| 10 |
+
# --- Sentinel Engine Functions ---
|
| 11 |
|
| 12 |
+
def generate_key(seed: str, dimensions: int = 5):
|
| 13 |
+
"""Sentinel multi-dimensional key derivation"""
|
| 14 |
kdf = PBKDF2HMAC(
|
| 15 |
+
algorithm=hashes.SHA256(),
|
| 16 |
+
length=32,
|
| 17 |
+
salt=b'sentinel_salt', # change to a secure static salt or dynamic
|
| 18 |
+
iterations=200000, # higher iterations for quantum resilience
|
| 19 |
+
backend=default_backend()
|
| 20 |
)
|
| 21 |
key = kdf.derive(seed.encode())
|
| 22 |
+
# Multi-dimensional expansion (adaptive randomness)
|
| 23 |
key += bytes([random.randint(0, 255) for _ in range(dimensions * 16)])
|
| 24 |
return key[:32]
|
| 25 |
|
| 26 |
+
def encrypt_data(data: bytes, key: bytes) -> bytes:
|
| 27 |
+
iv = os.urandom(16) # cryptographically secure IV
|
|
|
|
| 28 |
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
|
| 29 |
encryptor = cipher.encryptor()
|
| 30 |
|
| 31 |
+
padding_len = 16 - len(data) % 16
|
| 32 |
+
data += bytes([padding_len] * padding_len)
|
| 33 |
|
| 34 |
+
encrypted = encryptor.update(data) + encryptor.finalize()
|
| 35 |
+
return iv + encrypted
|
| 36 |
|
| 37 |
+
def decrypt_data(encrypted_data: bytes, key: bytes) -> bytes:
|
|
|
|
| 38 |
iv = encrypted_data[:16]
|
| 39 |
encrypted_data = encrypted_data[16:]
|
| 40 |
|
| 41 |
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
|
| 42 |
decryptor = cipher.decryptor()
|
| 43 |
+
decrypted = decryptor.update(encrypted_data) + decryptor.finalize()
|
| 44 |
+
|
| 45 |
+
padding_len = decrypted[-1]
|
| 46 |
+
return decrypted[:-padding_len]
|
| 47 |
|
| 48 |
+
# --- Streamlit UI ---
|
| 49 |
+
|
| 50 |
+
# Display Logo
|
| 51 |
+
st.image(
|
| 52 |
+
"https://huggingface.co/spaces/taarhissian/SentinelCryptography/resolve/main/sentinelcryptography.png",
|
| 53 |
+
caption="SentinelCryptography Logo",
|
| 54 |
+
use_container_width=True
|
| 55 |
+
)
|
| 56 |
|
|
|
|
|
|
|
| 57 |
st.title("π‘ SentinelCryptography")
|
| 58 |
st.subheader("A Quantum-Ready Encryption Guardian")
|
| 59 |
st.write("""
|
| 60 |
+
SentinelCryptography is not just an AES tool β it is a living sentinel, designed to protect your messages
|
| 61 |
+
today and withstand the cryptographic challenges of tomorrow.
|
| 62 |
""")
|
| 63 |
|
| 64 |
+
# --- Session State for Seed ---
|
| 65 |
+
if "seed" not in st.session_state:
|
| 66 |
+
st.session_state.seed = ""
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
# --- Encryption Section ---
|
| 69 |
+
st.markdown("---")
|
| 70 |
+
st.header("π Encrypt a Message")
|
| 71 |
+
message = st.text_area("Enter Message to Encrypt:")
|
| 72 |
+
st.session_state.seed = st.text_input("Enter Seed/Password for Key Generation:", st.session_state.seed)
|
| 73 |
+
|
| 74 |
+
if st.button("Encrypt"):
|
| 75 |
+
if message and st.session_state.seed:
|
| 76 |
+
key = generate_key(st.session_state.seed, dimensions=5)
|
| 77 |
+
encrypted = encrypt_data(message.encode(), key)
|
| 78 |
+
st.success("β
Encryption Complete!")
|
| 79 |
+
st.code(base64.b64encode(encrypted).decode(), language="text")
|
| 80 |
+
else:
|
| 81 |
+
st.error("Please enter both a message and a seed/password.")
|
| 82 |
+
|
| 83 |
+
# --- Decryption Section ---
|
| 84 |
+
st.markdown("---")
|
| 85 |
+
st.header("π Decrypt a Message")
|
| 86 |
+
encrypted_input = st.text_area("Enter Encrypted Message (Base64):")
|
| 87 |
+
|
| 88 |
+
if st.button("Decrypt"):
|
| 89 |
+
if encrypted_input and st.session_state.seed:
|
| 90 |
+
try:
|
| 91 |
+
encrypted_bytes = base64.b64decode(encrypted_input)
|
| 92 |
+
key = generate_key(st.session_state.seed, dimensions=5)
|
| 93 |
+
decrypted = decrypt_data(encrypted_bytes, key)
|
| 94 |
+
st.success("β
Decryption Complete!")
|
| 95 |
+
st.code(decrypted.decode(), language="text")
|
| 96 |
+
except Exception as e:
|
| 97 |
+
st.error(f"Decryption failed: {e}")
|
| 98 |
+
else:
|
| 99 |
+
st.error("Please enter both an encrypted message and the seed/password.")
|
| 100 |
+
|
| 101 |
+
# --- Educational & Roadmap Sections ---
|
| 102 |
st.markdown("---")
|
| 103 |
st.header("π The Legacy of Encryption")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
st.write("""
|
| 105 |
+
Encryption has evolved from ancient substitution ciphers to mechanical rotors in WWII,
|
| 106 |
+
and finally to AES in the modern era. SentinelCryptography pushes this evolution further,
|
| 107 |
+
preparing for the quantum era.
|
| 108 |
""")
|
| 109 |
|
|
|
|
| 110 |
st.markdown("---")
|
| 111 |
+
st.header("π Roadmap for 2025")
|
| 112 |
+
st.write("""
|
| 113 |
+
1. Q1: Expand post-quantum cryptographic support.
|
| 114 |
+
2. Q2: APIs for web & mobile integration.
|
| 115 |
+
3. Q3: Community challenges to improve security.
|
| 116 |
+
4. Q4: Launch full SentinelCryptography platform with analytics and advanced features.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
""")
|
| 118 |
+
st.image("https://via.placeholder.com/800x400.png?text=SentinelCryptography+2025+Roadmap")
|
| 119 |
|
| 120 |
+
# --- Donation Section ---
|
| 121 |
st.markdown("---")
|
| 122 |
+
st.header("π Support SentinelCryptography")
|
|
|
|
| 123 |
st.write("""
|
| 124 |
+
Your donations help us continue development and keep this project open source.
|
| 125 |
+
**Donate via Tether (USDT-ERC20)**: `0xD5255523b1A6a144D9d034c70735b2dB729B49f0`
|
| 126 |
+
Every contribution empowers global security for the quantum era.
|
|
|
|
| 127 |
""")
|
| 128 |
|
| 129 |
+
st.info("SentinelCryptography is open source. Together, we secure the future.")
|