import streamlit as st import hashlib import pandas as pd import qrcode from io import BytesIO from datetime import datetime import json import base64 # Set page config st.set_page_config( page_title="Document Integrity Checker", page_icon="🔐", layout="wide" ) # Custom CSS st.markdown(""" """, unsafe_allow_html=True) def calculate_hash(file_bytes): """Calculate SHA-256 hash of file""" sha256_hash = hashlib.sha256() sha256_hash.update(file_bytes) return sha256_hash.hexdigest() def generate_qr(data): """Generate QR code for hash""" qr = qrcode.QRCode(version=1, box_size=10, border=5) qr.add_data(data) qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") # Convert to bytes buffered = BytesIO() img.save(buffered, format="PNG") return buffered.getvalue() def save_to_history(filename, file_hash): """Save verification to history""" history = json.loads(st.session_state.get('history', '[]')) history.insert(0, { 'filename': filename, 'hash': file_hash, 'timestamp': datetime.now().isoformat() }) # Keep only last 10 entries history = history[:10] st.session_state['history'] = json.dumps(history) def get_history(): """Get verification history""" try: return json.loads(st.session_state.get('history', '[]')) except: return [] def main(): # Header st.title("🔐 Document Integrity Checker") st.markdown("Verifikasi & Lindungi Integritas Dokumen Anda dengan SHA-256") # Main content col1, col2 = st.columns([2, 1]) with col1: st.subheader("Upload Document") uploaded_files = st.file_uploader( "Drag and drop files here", accept_multiple_files=True, type=['pdf', 'doc', 'docx', 'txt', 'jpg', 'png'] ) if uploaded_files: for uploaded_file in uploaded_files: # Calculate hash file_bytes = uploaded_file.read() file_hash = calculate_hash(file_bytes) # Display hash st.markdown(f"**File:** {uploaded_file.name}") st.markdown(f"""