File size: 5,515 Bytes
e21cafd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ceb10c
e21cafd
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python3
"""
SecureX Light - Version simplifiée du système de détection de fraude
"""

import tkinter as tk
from tkinter import scrolledtext, messagebox
import re
import sqlite3
import json
from datetime import datetime

class FraudDetector:
    def __init__(self):
        self.patterns = [
            {
                "name": "fake_advisor",
                "keywords": ["conseiller", "banque", "urgent", "code"],
                "weight": 0.9
            },
            {
                "name": "fake_refund", 
                "keywords": ["remboursement", "argent", "code"],
                "weight": 0.85
            },
            {
                "name": "credential_theft",
                "keywords": ["mot de passe", "identifiant", "code secret"],
                "weight": 0.95
            }
        ]
        self.init_database()
    
    def init_database(self):
        """Crée une base de données SQLite simple"""
        self.conn = sqlite3.connect(":memory:")
        self.cursor = self.conn.cursor()
        self.cursor.execute("""
            CREATE TABLE IF NOT EXISTS calls (
                id INTEGER PRIMARY KEY,
                transcript TEXT,
                score REAL,
                timestamp DATETIME
            )
        """)
        self.conn.commit()
    
    def analyze_text(self, text):
        """Analyse le texte avec des motifs simples"""
        if not text:
            return 0.0
        
        text_lower = text.lower()
        total_score = 0.0
        
        for pattern in self.patterns:
            matches = sum(1 for word in pattern["keywords"] if word in text_lower)
            if matches > 0:
                total_score += (matches / len(pattern["keywords"])) * pattern["weight"]
        
        # Détection d'urgence
        urgency_words = ["urgent", "immédiat", "vite", "maintenant"]
        if sum(1 for word in urgency_words if word in text_lower) >= 2:
            total_score += 0.2
        
        return min(total_score, 1.0)
    
    def save_call(self, text, score):
        """Sauvegarde l'appel dans la base"""
        self.cursor.execute("""
            INSERT INTO calls (transcript, score, timestamp)
            VALUES (?, ?, ?)
        """, (text, score, datetime.now()))
        self.conn.commit()

class Application(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title("SecureX Light - Détection de Fraude")
        self.geometry("700x500")
        self.detector = FraudDetector()
        
        self.create_widgets()
    
    def create_widgets(self):
        """Crée l'interface utilisateur"""
        # Zone de texte pour l'entrée
        tk.Label(self, text="Transcript d'appel:").pack(pady=5)
        self.text_input = scrolledtext.ScrolledText(self, height=10)
        self.text_input.pack(fill=tk.X, padx=10, pady=5)
        
        # Boutons
        btn_frame = tk.Frame(self)
        btn_frame.pack(pady=10)
        
        tk.Button(btn_frame, text="Analyser", command=self.analyze).pack(side=tk.LEFT, padx=5)
        tk.Button(btn_frame, text="Exemple Fraude", command=self.load_fraud_example).pack(side=tk.LEFT, padx=5)
        tk.Button(btn_frame, text="Exemple Normal", command=self.load_normal_example).pack(side=tk.LEFT, padx=5)
        
        # Résultats
        tk.Label(self, text="Résultats:").pack(pady=5)
        self.result_text = scrolledtext.ScrolledText(self, height=10)
        self.result_text.pack(fill=tk.BOTH, expand=True, padx=10, pady=5)
    
    def analyze(self):
        """Lance l'analyse"""
        text = self.text_input.get("1.0", tk.END).strip()
        if not text:
            messagebox.showwarning("Attention", "Veuillez entrer un texte à analyser")
            return
        
        score = self.detector.analyze_text(text)
        self.detector.save_call(text, score)
        
        # Affichage des résultats
        self.result_text.delete("1.0", tk.END)
        
        if score > 0.7:
            result = f"🚨 ALERTE FRAUDE (Score: {score:.0%})\n\n"
            result += "Indicateurs détectés:\n"
            result += "- Langage urgent ou pressant\n"
            result += "- Demande d'informations sensibles\n"
            result += "\nAction recommandée: Terminer l'appel et contacter votre banque"
        elif score > 0.4:
            result = f"⚠️ RISQUE MODÉRÉ (Score: {score:.0%})\n\n"
            result += "Soyez prudent et ne donnez pas d'informations personnelles"
        else:
            result = f"✅ APPEL NORMAL (Score: {score:.0%})\n\n"
            result += "Aucun indicateur de fraude détecté"
        
        self.result_text.insert(tk.END, result)
    
    def load_fraud_example(self):
        """Charge un exemple frauduleux"""
        example = ("Bonjour, je suis votre conseiller bancaire. Nous avons détecté une activité "
                  "suspecte. Pour sécuriser votre compte, veuillez confirmer votre code secret IMMÉDIATEMENT.")
        self.text_input.delete("1.0", tk.END)
        self.text_input.insert("1.0", example)
    
    def load_normal_example(self):
        """Charge un exemple normal"""
        example = ("Bonjour, je vous appelle pour vous informer que votre carte bancaire "
                   "arrive à expiration. Souhaitez-vous recevoir la nouvelle par courrier ?")
        self.text_input.delete("1.0", tk.END)
        self.text_input.insert("1.0", example)
        

if __name__ == "__main__":
    app = Application()
    app.mainloop()