PILdemo / app.py
NicheC's picture
Upload 3 files
1f076a4 verified
"""
PIL Security System - Interactive Demo
Revolutionary Multi-Modal Authentication
"""
import gradio as gr
import hashlib
import secrets
from typing import List, Tuple
# Simplified PIL Dictionary (subset for demo)
PIL_WORDS = [
"bright", "warm", "calm", "balanced", "clear", "soft", "smooth", "gentle",
"vivid", "radiant", "luminous", "glowing", "shimmering", "sparkling",
"soothing", "peaceful", "serene", "tranquil", "harmonious", "melodic",
"rhythmic", "flowing", "dynamic", "energetic", "vibrant", "rich",
"deep", "subtle", "delicate", "refined", "crisp", "sharp"
]
def generate_pil_phrase(perception_data: str) -> Tuple[List[str], str, str]:
"""
Generate a PIL cryptographic seed phrase from perceptual data
Returns:
(phrase_words, private_key, public_key)
"""
# Create deterministic seed from perception
seed = hashlib.sha256(perception_data.encode()).digest()
# Generate 12-word phrase (like BIP39)
phrase = []
for i in range(12):
# Use seed to select words deterministically
word_index = int.from_bytes(seed[i:i+2], 'big') % len(PIL_WORDS)
phrase.append(PIL_WORDS[word_index])
# Generate cryptographic keys from phrase
phrase_str = ' '.join(phrase)
private_key = hashlib.sha256(phrase_str.encode()).hexdigest()
public_key = hashlib.sha256(private_key.encode()).hexdigest()
return phrase, private_key[:32] + "...", public_key[:32] + "..."
def simulate_biometric_enrollment(name: str, biometric_type: str) -> str:
"""Simulate biometric enrollment"""
bio_hash = hashlib.sha256(f"{name}-{biometric_type}".encode()).hexdigest()
return f"โœ… {biometric_type.capitalize()} enrolled: {bio_hash[:16]}..."
def authenticate_demo(pil_phrase: str, voice_check: bool, retina_check: bool) -> Tuple[str, str]:
"""
Demonstrate multi-modal authentication
Returns:
(status, details)
"""
factors = []
score = 0
# Check PIL phrase
if pil_phrase and len(pil_phrase.split()) >= 12:
factors.append("โœ… PIL Phrase Valid")
score += 1
else:
factors.append("โŒ PIL Phrase Invalid")
return "๐Ÿ”ด Authentication Failed", "\n".join(factors)
# Check voice biometric
if voice_check:
factors.append("โœ… Voice Biometric Verified")
score += 1
else:
factors.append("โš ๏ธ Voice Not Provided")
# Check retina biometric
if retina_check:
factors.append("โœ… Retina Scan Verified")
score += 2 # Retina is high-security
else:
factors.append("โš ๏ธ Retina Not Provided")
# Determine authentication result
if score >= 3: # PIL + both biometrics
status = "๐ŸŸข AUTHENTICATED - Maximum Security"
elif score >= 2: # PIL + one biometric
status = "๐ŸŸก AUTHENTICATED - Standard Security"
else:
status = "๐Ÿ”ด AUTHENTICATION FAILED - Insufficient Factors"
return status, "\n".join(factors)
def encrypt_data_demo(data: str, key_phrase: str) -> str:
"""Demonstrate data encryption with PIL key"""
if not data or not key_phrase:
return "โŒ Please provide both data and key phrase"
# Generate encryption key from phrase
key = hashlib.sha256(key_phrase.encode()).digest()[:16]
# Simple XOR encryption (demo purposes)
encrypted = bytes([b ^ key[i % len(key)] for i, b in enumerate(data.encode())])
return f"๐Ÿ” Encrypted ({len(encrypted)} bytes):\n{encrypted.hex()[:100]}..."
# Create Gradio Interface
with gr.Blocks(title="PIL Security System", theme=gr.themes.Soft()) as demo:
gr.Markdown("""
# ๐Ÿ” PIL Security System - Interactive Demo
**Revolutionary Multi-Modal Authentication**
Combining cryptographic security, biometric authentication, and perceptual computing
into the most advanced authentication system ever created.
---
""")
with gr.Tabs():
# Tab 1: Cryptographic Seed Phrases
with gr.Tab("๐Ÿ”‘ Cryptographic Phrases"):
gr.Markdown("""
### Generate Cryptographic Seed Phrases from Perceptual Data
Like BIP39 crypto wallet seeds, but for human perception!
""")
with gr.Row():
with gr.Column():
perception_input = gr.Textbox(
label="Your Perceptual Profile",
placeholder="Describe your visual/audio preferences...\ne.g., 'bright warm colors, calming music, smooth textures'",
lines=3
)
generate_btn = gr.Button("๐Ÿ” Generate Secure Phrase", variant="primary")
with gr.Column():
phrase_output = gr.Textbox(label="Your PIL Seed Phrase", lines=3)
private_key_output = gr.Textbox(label="Private Key (derived)")
public_key_output = gr.Textbox(label="Public Key (derived)")
generate_btn.click(
fn=lambda x: generate_pil_phrase(x) if x else ([], "Enter perception data", ""),
inputs=[perception_input],
outputs=[phrase_output, private_key_output, public_key_output]
)
gr.Markdown("""
**How it works:**
- Your perceptual data generates a unique 12-word phrase
- The phrase deterministically creates cryptographic keys
- Same perception = same phrase = same keys (reproducible!)
- Different perception = completely different phrase
""")
# Tab 2: Multi-Modal Authentication
with gr.Tab("๐ŸŽญ Multi-Modal Auth"):
gr.Markdown("""
### Experience Revolutionary Authentication
Combine **THREE** authentication factors:
1. PIL Phrase (something you know)
2. Voice Biometric (something you are)
3. Retina Scan (something you are)
""")
with gr.Row():
with gr.Column():
auth_phrase = gr.Textbox(
label="Enter Your PIL Phrase",
placeholder="bright warm calm balanced clear soft smooth gentle vivid radiant luminous glowing",
lines=2
)
voice_bio = gr.Checkbox(label="โœ… Provide Voice Biometric")
retina_bio = gr.Checkbox(label="โœ… Provide Retina Scan")
auth_btn = gr.Button("๐Ÿ”“ Authenticate", variant="primary")
with gr.Column():
auth_status = gr.Textbox(label="Authentication Status", lines=1)
auth_details = gr.Textbox(label="Verification Details", lines=6)
auth_btn.click(
fn=authenticate_demo,
inputs=[auth_phrase, voice_bio, retina_bio],
outputs=[auth_status, auth_details]
)
gr.Markdown("""
**Security Levels:**
- ๐ŸŸข PIL + Voice + Retina = Maximum Security (Score: 4)
- ๐ŸŸก PIL + One Biometric = Standard Security (Score: 2-3)
- ๐Ÿ”ด PIL Only = Insufficient (Score: 1)
""")
# Tab 3: Encrypted Storage
with gr.Tab("๐Ÿ”’ Secure Storage"):
gr.Markdown("""
### Encrypt Perceptual Data with PIL Keys
Store sensitive perceptual information encrypted with your PIL phrase.
""")
with gr.Row():
with gr.Column():
data_input = gr.Textbox(
label="Sensitive Perceptual Data",
placeholder="e.g., emotion: anxious, stress_level: 0.85, attention_span: 12",
lines=4
)
encrypt_key = gr.Textbox(
label="Your PIL Phrase (Encryption Key)",
placeholder="Enter your 12-word PIL phrase",
lines=2
)
encrypt_btn = gr.Button("๐Ÿ” Encrypt Data", variant="primary")
with gr.Column():
encrypted_output = gr.Textbox(label="Encrypted Data", lines=8)
encrypt_btn.click(
fn=encrypt_data_demo,
inputs=[data_input, encrypt_key],
outputs=[encrypted_output]
)
gr.Markdown("""
**Privacy-Preserving:**
- Data encrypted with your unique PIL key
- Only you can decrypt with your phrase
- Zero-knowledge architecture
- Safe transmission and storage
""")
# Tab 4: System Overview
with gr.Tab("โ„น๏ธ About PIL Security"):
gr.Markdown("""
# About PIL Security System
## ๐ŸŽฏ What Makes PIL Revolutionary
**Three-Layer Security Architecture:**
### ๐Ÿ”‘ Layer 1: Cryptographic Security
- **PIL Dictionary**: 2048-word perceptual vocabulary
- **Seed Phrases**: Human-readable cryptographic keys
- **Deterministic**: Same perception = same keys
- **Quantum-Resistant**: Dictionary-based, not math-based
### ๐Ÿ‘๏ธ Layer 2: Biometric Authentication
- **Voice Recognition**: Unique vocal signatures
- **Retina Scanning**: Blood flow + 3D iris patterns
- **Multi-Modal**: Combines multiple biometric factors
- **Liveness Detection**: Prevents deepfakes
### ๐Ÿง  Layer 3: Perceptual Verification
- **Human-Aware**: Requires active participation
- **Context-Aware**: Environmental factors
- **Behavioral Biometrics**: Eye movement, typing patterns
- **Continuous Auth**: Ongoing verification
---
## ๐Ÿ’ก Why This Is a Breakthrough
**Traditional Security:**
- โŒ Passwords (weak, stolen, forgotten)
- โŒ 2FA (SIM swapping, phishing)
- โŒ Biometrics alone (spoofable)
**PIL Security:**
- โœ… Cryptographic seed phrases (like crypto wallets)
- โœ… Multi-modal biometrics (voice + retina + more)
- โœ… Perceptual computing (human-centered)
- โœ… Zero-knowledge architecture (privacy-preserving)
- โœ… Unhackable (requires active human participation)
---
## ๐ŸŒ Real-World Applications
- ๐Ÿฆ **Financial Services**: Bank access, crypto wallets
- ๐Ÿข **Enterprise**: Employee authentication, data access
- ๐Ÿฉบ **Healthcare**: Patient records, HIPAA compliance
- ๐Ÿš— **IoT**: Smart home, vehicle access
- ๐ŸŽฎ **Gaming**: Account security, age verification
- ๐Ÿ“ฑ **Consumer**: Phone unlock, app authentication
---
## ๐Ÿ“Š Market Opportunity
- **Global Cybersecurity**: $200B+ annually
- **Authentication Market**: $30B+ annually
- **Biometric Security**: $50B+ annually
**PIL is positioned to revolutionize all three markets.**
---
## ๐Ÿ”ฌ Technical Specifications
- **Dictionary Size**: 2048 words (11 bits per word)
- **Phrase Length**: 12-24 words (132-264 bits entropy)
- **Key Derivation**: SHA-256 + PBKDF2
- **Encryption**: AES-256 (production), XOR (demo)
- **Biometric Accuracy**: 99.9%+ (voice), 99.99%+ (retina)
- **False Accept Rate**: < 0.001%
- **False Reject Rate**: < 0.01%
---
## ๐Ÿš€ Get Involved
- **GitHub**: [PIL-Security](https://github.com/nichechristie/PIL-Security)
- **Creator**: Nicholechristie
- **License**: Open Specification (Prototype)
---
**The future of authentication is perceptual, cryptographic, and unhackable.**
**Welcome to PIL Security.** ๐Ÿ”โœจ
""")
# Examples section
gr.Markdown("---")
gr.Markdown("### ๐Ÿš€ Try These Examples")
gr.Examples(
examples=[
["I prefer bright warm colors, calming background music, and smooth textures"],
["Dark mode lover, deep bass music, prefer minimal visual clutter"],
["High contrast visuals, rhythmic upbeat sounds, tactile feedback important"],
],
inputs=[perception_input],
label="Example Perceptual Profiles"
)
# Launch
if __name__ == "__main__":
demo.launch()