Download cognitive_deception_engine.py from secutorpro/SAQR-Cognitive-Spoofer: direct link, hf CLI and curl.
- Browser
- Download file 5.75 kB
-
https://huggingface.co/datasets/secutorpro/SAQR-Cognitive-Spoofer/resolve/main/cognitive_deception_engine.py
- Command line
-
hf download hf://datasets/secutorpro/SAQR-Cognitive-Spoofer/cognitive_deception_engine.py
-
curl -L -o cognitive_deception_engine.py https://huggingface.co/datasets/secutorpro/SAQR-Cognitive-Spoofer/resolve/main/cognitive_deception_engine.py
5.75 kB
| """ | |
| COGNITIVE DECEPTION ENGINE — Smooth GPS Takeover for C-UAS | |
| Author: ODAC Project / Morocco Sovereign C-UAS | |
| Context: HIL/SITL simulation only — no real emission (legal compliance ANRT) | |
| """ | |
| import numpy as np | |
| from dataclasses import dataclass | |
| from typing import Tuple | |
| class DroneState: | |
| """État estimé de la cible (votre ODAC envoie ça)""" | |
| lat: float # degrés | |
| lon: float # degrés | |
| alt: float # mètres | |
| vx: float # m/s (Est) | |
| vy: float # m/s (Nord) | |
| vz: float # m/s (vertical) | |
| innovation_gate: float = 5.0 # seuil chi2 du EKF cible (typique) | |
| class DeceptionParams: | |
| """Paramètres du leurrage cognitif""" | |
| sigma_gps: float = 1.5 # bruit GPS réel en mètres | |
| max_bias_rate: float = 0.15 # m/s² — accélération max du biais (crédibilité) | |
| raim_threshold: float = 3.0 # seuil de détection RAIM (mètres) | |
| capture_lat: float = 30.4215 # Ex: zone désertique Sud Maroc | |
| capture_lon: float = -5.8120 | |
| class CognitiveSpoofer: | |
| """Moteur de leurrage — génère des positions mensongères crédibles""" | |
| def __init__(self, params: DeceptionParams): | |
| self.p = params | |
| self.bias_vector = np.array([0.0, 0.0, 0.0]) # biais accumulé (E, N, U) | |
| self.takeover_step = 0 | |
| def _lla_to_enu(self, state: DroneState, target_lat: float, target_lon: float) -> np.ndarray: | |
| """Convertit la différence LLA → vecteur ENU local (mètres)""" | |
| R = 6371000 # rayon Terre | |
| dlat = np.radians(target_lat - state.lat) | |
| dlon = np.radians(target_lon - state.lon) | |
| e = dlon * R * np.cos(np.radians(state.lat)) | |
| n = dlat * R | |
| return np.array([e, n, 0.0]) | |
| def compute_spoofed_position(self, state: DroneState, dt: float) -> Tuple[float, float, float]: | |
| """ | |
| Retourne les coordonnées GPS mensongères à envoyer au drone. | |
| Logique : biais progressif restant sous les gates RAIM/innovation. | |
| """ | |
| self.takeover_step += 1 | |
| # 1. Vecteur vers la zone de capture (ENU) | |
| to_capture = self._lla_to_enu(state, self.p.capture_lat, self.p.capture_lon) | |
| distance = np.linalg.norm(to_capture[:2]) | |
| if distance < 10: # déjà dans la kill box | |
| return state.lat, state.lon, state.alt | |
| # 2. Direction unitaire vers la capture | |
| direction = to_capture / distance | |
| # 3. Calcul du biais incrémental (smooth — sous les seuils) | |
| # Règle cognitive : bias_rate ≤ sigma_gps / dt pour rester "dans le bruit" | |
| max_step = min(self.p.max_bias_rate * dt, self.p.sigma_gps * 0.8) | |
| # Phase d'accroche (steps 0-30) : très lent pour "aggripper" le filtre | |
| if self.takeover_step < 30: | |
| max_step *= (self.takeover_step / 30) ** 2 # rampe quadratique | |
| # 4. Application du biais | |
| self.bias_vector += direction * max_step | |
| # 5. Conversion biais ENU → delta LLA | |
| R = 6371000 | |
| dlat = np.degrees(self.bias_vector[1] / R) | |
| dlon = np.degrees(self.bias_vector[0] / (R * np.cos(np.radians(state.lat)))) | |
| dalt = self.bias_vector[2] | |
| # 6. Position mensongère (ce que le drone "croit") | |
| spoofed_lat = state.lat + dlat | |
| spoofed_lon = state.lon + dlon | |
| spoofed_alt = state.alt + dalt | |
| # 7. Vérification de crédibilité (self-check) | |
| innovation = np.linalg.norm(self.bias_vector[:2]) | |
| if innovation > self.p.raim_threshold: | |
| # Alerte interne : le drone va détecter — on ralentit | |
| self.bias_vector *= 0.95 | |
| return spoofed_lat, spoofed_lon, spoofed_alt | |
| def get_deception_telemetry(self) -> dict: | |
| """Télémétrie pour votre dashboard ODAC""" | |
| bias_m = np.linalg.norm(self.bias_vector) | |
| return { | |
| "bias_meters": round(bias_m, 2), | |
| "takeover_progress": min(100, int(bias_m / 10)), # % vers capture | |
| "status": "ACTIVE" if bias_m > 0 else "STANDBY", | |
| "credibility": "HIGH" if bias_m < self.p.raim_threshold else "RISK" | |
| } | |
| # ════════════════════════════════════════════════════════════ | |
| # DÉMO — Intégration dans votre boucle ODAC | |
| # ═══════════════════════════════════════════════════════════ | |
| if __name__ == "__main__": | |
| params = DeceptionParams( | |
| capture_lat=30.4215, # Kill Box — désert Sud Maroc | |
| capture_lon=-5.8120 | |
| ) | |
| spoofer = CognitiveSpoofer(params) | |
| # Piste PST-001 détectée par votre radar cognitif | |
| target = DroneState( | |
| lat=31.6295, lon=-8.0123, # Ex: survol zone Marrakech | |
| alt=120, vx=12, vy=-5, vz=0 | |
| ) | |
| print("🍯 HONEYPOT ACTIVATED — Smooth Takeover") | |
| print("=" * 50) | |
| dt = 1.0 # 1 Hz — rythme du spoofer | |
| for t in range(60): | |
| spoofed = spoofer.compute_spoofed_position(target, dt) | |
| telemetry = spoofer.get_deception_telemetry() | |
| if t % 10 == 0: | |
| print(f"T+{t:3d}s | Spoofed: {spoofed[0]:.6f}, {spoofed[1]:.6f} | " | |
| f"Bias: {telemetry['bias_meters']:5.1f}m | " | |
| f"Credibility: {telemetry['credibility']}") | |
| # Simulation du mouvement réel du drone | |
| target.lat += target.vy * dt / 111000 | |
| target.lon += target.vx * dt / (111000 * np.cos(np.radians(target.lat))) | |