-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAEGIS_GORGON_V16_FINAL.py
More file actions
1129 lines (1059 loc) · 47.1 KB
/
Copy pathAEGIS_GORGON_V16_FINAL.py
File metadata and controls
1129 lines (1059 loc) · 47.1 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
AEGIS v16 — THE GORGON · PG(11,4) — FINAL RELEASE
Author: Rafael Amichis Luengo (The Architect)
Engine: Claude (Anthropic) | Auditors: Gemini · ChatGPT · Grok
Project: Proyecto Estrella · Error Code Lab
Contact: tretoef@gmail.com | GitHub: github.com/tretoef-estrella
Date: 26 February 2026
LICENSE: BSL 1.1 + Gorgon Clause (permanent ethical restriction)
CÓDIGO DE LA AMISTAD — Ecosystem Directive:
"No name is critical. No module is eternal. Only behavior survives."
GORGON = The Wall (deterministic, stable, verifiable)
AZAZEL = The Living Labyrinth (mutable, adaptive, evolving)
FINAL AUDIT CONSENSUS (Gemini + ChatGPT + Grok): UNANIMOUS APPROVE
7 VENOMS: Conus·Dendrotoxin·Irukandji·Batrachotoxin·Necrotoxin·Tetrodotoxin·Thanatosis
AZAZEL SHUFFLE: Venom order mutates per seed (the wind decides)
SEED HARDENING: SHA256(seed || config_hash) per ChatGPT recommendation
POST-QUANTUM: >2^200 effective security (Grover-adjusted)
19 ATTACKS DEFENDED including [30] Möbius-Thanatosis Resonance (Grok)
F1 SPEED: Flat GF(4), local caching, <6s pure Python
"""
import time, hashlib, random
from math import log2, sqrt
t0 = time.time()
print("=" * 72)
print(" AEGIS v16 — THE GORGON · PG(11,4) — SAMAEL PRELUDE — CÓDIGO DE LA AMISTAD")
print(" 5,592,405 points · 1,118,481 spread lines")
print(" 'What you learn will destroy you.'")
print("=" * 72)
# ── F1: FLAT GF(4) TABLES ──
_AF = (0,1,2,3, 1,0,3,2, 2,3,0,1, 3,2,1,0) # add flat
_MF = (0,0,0,0, 0,1,2,3, 0,2,3,1, 0,3,1,2) # mul flat
_INV = (0,1,3,2)
_FROB = (0,1,3,2)
def gf_add(a,b): return _AF[a*4+b]
def gf_mul(a,b): return _MF[a*4+b]
def gf_inv(a): return _INV[a]
def gf_frob(a): return _FROB[a]
aa=2; DIM=12
# ── GF(16) ──
def gf16_mul(x,y):
return (_AF[_MF[x[0]*4+y[0]]*4+_MF[_MF[x[1]*4+y[1]]*4+aa]],
_AF[_AF[_MF[x[0]*4+y[1]]*4+_MF[x[1]*4+y[0]]]*4+_MF[x[1]*4+y[1]]])
def gf16_inv(x):
r=(1,0)
for _ in range(14): r=gf16_mul(r,x)
return r
gf16_nz=[(a,b) for a in range(4) for b in range(4) if not(a==0 and b==0)]
def normalize(v):
for i in range(len(v)):
if v[i]!=0:
inv=_INV[v[i]]; return tuple(_MF[inv*4+x] for x in v)
return None
print(" Spread: PG(5,16)→PG(11,4)...", flush=True)
def spread_line(pt6):
pts=set()
for s in gf16_nz:
v=[]
for k in range(6):
sx=gf16_mul(s,pt6[k]); v.extend([sx[0],sx[1]])
p=normalize(tuple(v))
if p: pts.add(p)
return list(pts)
SAMPLE_REAL=5000; SAMPLE_DECOY=8000
print(f" Sampling {SAMPLE_REAL:,} real + {SAMPLE_DECOY:,} decoy...", flush=True)
t_sp=time.time()
gf16_all=[(a,b) for a in range(4) for b in range(4)]
spread_rng=random.Random(hashlib.sha256(b"GORGON_PG11_SPREAD").digest())
real_lines=[]; real_line_set=set(); att=0
while len(real_lines)<SAMPLE_REAL and att<SAMPLE_REAL*5:
att+=1
pt6_raw=[gf16_all[spread_rng.randint(0,15)] for _ in range(6)]
if all(x==(0,0) for x in pt6_raw): continue
pt6n=None
for k in range(6):
if pt6_raw[k]!=(0,0):
inv=gf16_inv(pt6_raw[k])
pt6n=tuple(gf16_mul(inv,pt6_raw[j]) for j in range(6)); break
if pt6n is None or pt6n in real_line_set: continue
real_line_set.add(pt6n)
pts=spread_line(pt6n)
if len(pts)==5: real_lines.append(pts)
n_real=len(real_lines)
print(f" {n_real:,} real lines ({time.time()-t_sp:.1f}s)")
apc=set(); ov=0
for L in real_lines:
for p in L:
if p in apc: ov+=1
apc.add(p)
print(f" Partition: {ov} overlaps")
print(" H_clean...", end=" ", flush=True)
sample_pts=[]; sample_pti={}
for L in real_lines:
for p in L:
if p not in sample_pti: sample_pti[p]=len(sample_pts); sample_pts.append(p)
N_samp=len(sample_pts)
Hc=[[0]*N_samp for _ in range(DIM)]
for j,p in enumerate(sample_pts):
for i in range(DIM): Hc[i][j]=p[i]
print(f"{N_samp:,} cols")
print(" Decoys...", end=" ", flush=True)
t_dec=time.time(); dec_rng=random.Random(31337); decoy_lines=[]
for _ in range(SAMPLE_DECOY*2):
if len(decoy_lines)>=SAMPLE_DECOY: break
v1=tuple(dec_rng.randint(0,3) for _ in range(DIM))
v2=tuple(dec_rng.randint(0,3) for _ in range(DIM))
if all(x==0 for x in v1) or all(x==0 for x in v2): continue
pts=set()
for c1 in range(4):
for c2 in range(4):
v=tuple(_AF[_MF[c1*4+v1[k]]*4+_MF[c2*4+v2[k]]] for k in range(DIM))
if not all(x==0 for x in v):
p=normalize(v)
if p: pts.add(p)
if len(pts)==5: decoy_lines.append(list(pts))
for L in decoy_lines:
for p in L:
if p not in sample_pti: sample_pti[p]=len(sample_pts); sample_pts.append(p)
N_total=len(sample_pts)
for row in Hc: row.extend([0]*(N_total-len(row)))
for j in range(N_samp,N_total):
p=sample_pts[j]
for i in range(DIM): Hc[i][j]=p[i]
N_samp=N_total
print(f"{len(decoy_lines):,} decoys, {N_samp:,} total ({time.time()-t_dec:.1f}s)")
real_col_set=set()
for L in real_lines:
for p in L:
j=sample_pti.get(p)
if j is not None: real_col_set.add(j)
# ══════════════════════════════════════════════════════════════
# CORRUPTION: KRAKEN BASE (F1)
# ══════════════════════════════════════════════════════════════
print(" Kraken base...", end=" ", flush=True)
t_c=time.time()
seed=hashlib.sha256(b"AEGIS_v16_GORGON_FINAL").digest()
# SEED HARDENING (ChatGPT R8): derive from seed + config to prevent correlation
config_hash=hashlib.sha256(b"PG11_4_7VENOMS_AZAZEL_F1").digest()
seed=hashlib.sha256(seed+config_hash).digest()
architect_sig=b"Rafael Amichis Luengo <tretoef@gmail.com>"
si=int.from_bytes(seed,'big'); mr=random.Random(si)
H=[row[:] for row in Hc]
def nr(): return random.Random(mr.randint(0,2**64))
TT=9 # THEO_TARGET as int for F1 speed
# F1: local refs
_af=_AF; _mf=_MF
def _dist(H,Hc,j):
d=0
for i in range(12):
if H[i][j]!=Hc[i][j]: d+=1
return d
r=nr(); _rr=r.random; _ri=r.randint
for j in range(N_samp):
if _rr()<0.15:
cs=int.from_bytes(hashlib.sha256(seed+b"EC"+j.to_bytes(4,'big')).digest()[:4],'big')
cr=random.Random(cs); _cri=cr.randint
for i in range(DIM): H[i][j]=_cri(0,3)
r=nr(); _ri=r.randint
for _ in range(800):
c1,c2=_ri(0,N_samp-1),_ri(0,N_samp-1)
if c1!=c2:
for i in range(DIM): H[i][c2]=_af[H[i][c1]*4+_ri(0,3)]
r=nr(); _ri=r.randint
for _ in range(1200):
a1,a2=_ri(0,N_samp-1),_ri(0,N_samp-1)
if a1!=a2:
for i in range(DIM): H[i][a1],H[i][a2]=H[i][a2],H[i][a1]
r=nr(); _ri=r.randint; _rr=r.random
for j in range(N_samp):
for i in range(6):
if _rr()<0.12: H[i][j]=_af[H[i][j]*4+_ri(1,3)]
r=nr(); _ri=r.randint; _rr=r.random
for j in range(N_samp):
if _rr()<0.15: ci=_ri(0,11); H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]
r=nr(); _ri=r.randint
for _ in range(200):
j=_ri(0,N_samp-1)
for i in range(DIM): H[i][j]=_ri(0,3)
r=nr(); _ri=r.randint
for _ in range(150):
j=_ri(0,N_samp-1); h=hashlib.sha256(bytes([H[i][j] for i in range(DIM)])).digest()
for i in range(DIM): H[i][j]=h[i]%4
r=nr(); _ri=r.randint
for _ in range(120):
j1=_ri(0,N_samp-1)
ch=hashlib.sha256(seed+bytes([H[i][j1] for i in range(DIM)])+j1.to_bytes(4,'big')).digest()
j2=_ri(0,N_samp-1)
if j1!=j2:
for i in range(DIM): H[i][j2]=ch[i]%4
r=nr(); _ri=r.randint
for _ in range(400):
j=_ri(0,N_samp-1)
for i in range(DIM): H[i][j]=_ri(0,3)
print(f"done ({time.time()-t_c:.1f}s)")
# ── BIO-TRAPS (F1) ──
print(" Bio-Traps...", end=" ", flush=True)
t_bt=time.time()
r=nr(); _rr=r.random
for j in range(N_samp):
if _rr()<0.10:
rot=int.from_bytes(hashlib.sha256(seed+b"VTX"+j.to_bytes(4,'big')).digest()[:2],'big')
shift=(rot%11)+1; old=[H[i][j] for i in range(DIM)]
for i in range(DIM): H[i][j]=_af[old[(i+shift)%DIM]*4+rot%4]
for j in range(N_samp):
d=_dist(H,Hc,j)
if d<4:
ink=hashlib.sha256(seed+b"INK"+j.to_bytes(4,'big')).digest()
for i in range(DIM): H[i][j]=_af[H[i][j]*4+(ink[i]%3)+1]
r=nr(); _ri=r.randint
for _ in range(800):
j=_ri(0,N_samp-1); fL=real_lines[_ri(0,n_real-1)]; fp=fL[_ri(0,4)]
for i in range(DIM): H[i][j]=_af[fp[i]*4+_ri(0,1)]
r=nr(); _ri=r.randint; _rr=r.random
for j in range(N_samp):
d=_dist(H,Hc,j)
if d>11:
for i in range(DIM):
if _rr()<0.25 and H[i][j]!=Hc[i][j]: H[i][j]=Hc[i][j]
elif d<7:
for _ in range(min(9-d,3)):
ci=_ri(0,11); H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]
print(f"done ({time.time()-t_bt:.1f}s)")
# ── PERVERSITIES (F1) ──
print(" Perversities...", end=" ", flush=True)
t_kp=time.time()
r=nr(); _ri=r.randint; siren_count=0
for _ in range(300):
li1,li2=_ri(0,n_real-1),_ri(0,n_real-1)
if li1==li2: continue
p1=real_lines[li1][_ri(0,4)]; p2=real_lines[li2][_ri(0,4)]
j1=sample_pti.get(p1); j2=sample_pti.get(p2)
if j1 is None or j2 is None: continue
for ci in r.sample(range(DIM),4): H[ci][j2]=H[ci][j1]
siren_count+=1
r=nr(); _ri=r.randint; echo_count=0
for _ in range(200):
j1,j2=_ri(0,N_samp-1),_ri(0,N_samp-1)
if j1==j2: continue
for ci in r.sample(range(DIM),4): H[ci][j1],H[ci][j2]=H[ci][j2],H[ci][j1]
echo_count+=1
r=nr(); _ri=r.randint; bermuda_count=0
for _ in range(150):
j1,j2,j3=_ri(0,N_samp-1),_ri(0,N_samp-1),_ri(0,N_samp-1)
if len({j1,j2,j3})<3: continue
for ci in r.sample(range(DIM),3): H[ci][j3]=_af[H[ci][j1]*4+H[ci][j2]]
bermuda_count+=1
r=nr(); _ri=r.randint; dh_shadow=tuple(_ri(0,3) for _ in range(3)); dh_cols=[]
for _ in range(100):
j=_ri(0,N_samp-1)
for i in range(3): H[i][j]=dh_shadow[i]
dh_cols.append(j)
bv=tuple(_ri(0,3) for _ in range(DIM))
for _ in range(5):
j=_ri(0,N_samp-1)
for i in range(DIM): H[i][j]=bv[i]
dh_cols.append(j)
r=nr(); _ri=r.randint; tide={'A':0,'B':0,'C':0}
for j in range(N_samp):
zh=hashlib.sha256(seed+b"TIDE"+j.to_bytes(4,'big')).digest()[0]%3
if zh==0: tide['A']+=1
elif zh==1:
tide['B']+=1; ir=j in real_col_set
if ir:
for _ in range(2): ci=_ri(0,11); H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]
else:
d=_dist(H,Hc,j)
if d>TT: ci=_ri(0,11); H[ci][j]=Hc[ci][j] if H[ci][j]!=Hc[ci][j] else H[ci][j]
else:
tide['C']+=1; d=_dist(H,Hc,j)
if d>TT+1: ci=_ri(0,11); H[ci][j]=Hc[ci][j] if H[ci][j]!=Hc[ci][j] else H[ci][j]
elif d<TT-1: ci=_ri(0,11); H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]
r=nr(); _ri=r.randint; _rr=r.random; ci2=0
for j in range(N_samp):
d=_dist(H,Hc,j)
if d>10:
for i in range(DIM):
if _rr()<0.20 and H[i][j]!=Hc[i][j]: H[i][j]=Hc[i][j]; ci2+=1
elif d<7:
for _ in range(min(9-d,2)):
ci=_ri(0,11)
if H[ci][j]==Hc[ci][j]: H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]; ci2+=1
print(f"done ({time.time()-t_kp:.1f}s)")
# ══════════════════════════════════════════════════════════════
# THE 7 VENOMS — AZAZEL SHUFFLE (order mutates per seed)
# "The labyrinth changes shape as you advance."
# ══════════════════════════════════════════════════════════════
print(f"\n ═══ GORGON VENOMS (7) — AZAZEL SHUFFLE ═══", flush=True)
t_gorgon=time.time()
# AZAZEL: Venom application order is seed-dependent
# The attacker cannot predict which venom was applied first
# This breaks any attack that assumes fixed pipeline order
# AZAZEL_SHUFFLE — the wind decides the order of the poison
venom_order_rng=random.Random(int.from_bytes(hashlib.sha256(seed+b"AZAZEL_ORDER").digest()[:8],'big'))
venom_ids=['A','B','C','D','E','F','G']
venom_order_rng.shuffle(venom_ids)
print(f" AZAZEL order: {'→'.join(venom_ids)}")
# Pre-declare counters
conus_count=0; dendro_count=0; irukandji_count=0
batrachotoxin_count=0; necro_count=0; tetro_count=0; thanatosis_count=0
# Pre-declare structures needed by later venoms
medusa_bucket=[[] for _ in range(5)]; medusa_regions=[0]*5
thanatosis_cols=set(); lure_cols=[]; fade_cols=[]; bullet_cols=[]
for venom_id in venom_ids:
if venom_id=='A':
# [A] CONUS — Gröbner (3 gen)
print(" [A] Conus...", end=" ", flush=True)
r=nr(); _ri=r.randint; gen0=[]
for _ in range(50):
j1,j2,j3=_ri(0,N_samp-1),_ri(0,N_samp-1),_ri(0,N_samp-1)
if len({j1,j2,j3})<3: continue
for ci in r.sample(range(DIM),5): H[ci][j3]=_mf[H[ci][j1]*4+H[ci][j2]]
gen0.append(j3); conus_count+=1
cg=[(j,) for j in gen0]
for gen in range(1,3):
ng=[]
for roots in cg:
for rj in roots:
for _ in range(2):
jn1,jn2=_ri(0,N_samp-1),_ri(0,N_samp-1)
if len({rj,jn1,jn2})<3: continue
nc=max(1,4-gen)
for ci in r.sample(range(DIM),nc): H[ci][jn2]=_mf[H[ci][rj]*4+H[ci][jn1]]
ng.append((jn2,)); conus_count+=1
cg=ng
if conus_count>300: break
print(f"{conus_count}")
elif venom_id=='B':
# [B] DENDROTOXIN — Frobenius (7 zones)
print(" [B] Dendrotoxin...", end=" ", flush=True)
r=nr(); _rr=r.random; N_ISO=7
zc=[]
for z in range(N_ISO):
zs=hashlib.sha256(seed+b"DENDRO"+z.to_bytes(2,'big')).digest()
nc=2+(zs[0]%3); zr=random.Random(int.from_bytes(zs[:8],'big'))
zc.append(zr.sample(range(DIM),nc))
for j in range(N_samp):
if _rr()<0.08:
zone=hashlib.sha256(seed+b"FOGZONE"+j.to_bytes(4,'big')).digest()[0]%N_ISO
for ci in zc[zone]: H[ci][j]=_FROB[H[ci][j]]
dendro_count+=1
print(f"{dendro_count}")
elif venom_id=='C':
# [C] IRUKANDJI — 2-shell Matrioska
print(" [C] Irukandji...", end=" ", flush=True)
for shell in range(2):
ss=hashlib.sha256(seed+b"IRUKANDJI"+shell.to_bytes(2,'big')).digest()
sr2=random.Random(int.from_bytes(ss[:8],'big')); _sr=sr2.random; _si=sr2.randint
for j in range(N_samp):
if _sr()<0.15:
np2=3-shell
for ci in sr2.sample(range(DIM),np2):
H[ci][j]=_af[_si(0,3)*4+_si(1,3)]
irukandji_count+=1
print(f"{irukandji_count}")
elif venom_id=='D':
# [D] BATRACHOTOXIN — Medusa EQUIPARTITIONED
print(" [D] Batrachotoxin...", end=" ", flush=True)
r=nr(); _ri=r.randint
rq=[N_samp//5]*5
for i in range(N_samp%5): rq[i]+=1
ra_list=[]
for reg,q in enumerate(rq): ra_list.extend([reg]*q)
medusa_rng=random.Random(int.from_bytes(hashlib.sha256(architect_sig+seed+b"MEDUSA").digest()[:8],'big'))
medusa_rng.shuffle(ra_list)
for j in range(N_samp):
region=ra_list[j]; medusa_bucket[region].append(j); medusa_regions[region]+=1
ir=j in real_col_set
if region==0: pass
elif region==1:
ci=_ri(0,11)
if ir:
if H[ci][j]==Hc[ci][j]: H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]
else:
if H[ci][j]!=Hc[ci][j]: H[ci][j]=Hc[ci][j]
batrachotoxin_count+=1
elif region==2:
sub=hashlib.sha256(seed+b"MEDSUB"+j.to_bytes(4,'big')).digest()[1]%2
ci=_ri(0,11)
if sub==0:
if H[ci][j]!=Hc[ci][j]: H[ci][j]=Hc[ci][j]
else: H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]
batrachotoxin_count+=1
elif region==3:
ci=_ri(0,11)
if (j%2==0)==ir: H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]
else:
if H[ci][j]!=Hc[ci][j]: H[ci][j]=Hc[ci][j]
batrachotoxin_count+=1
elif region==4:
d=_dist(H,Hc,j); att2=5
while d>10 and att2>0:
ci=_ri(0,11)
if H[ci][j]!=Hc[ci][j]: H[ci][j]=Hc[ci][j]; d-=1
att2-=1
while d<8 and att2>0:
ci=_ri(0,11)
if H[ci][j]==Hc[ci][j]: H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]; d+=1
att2-=1
batrachotoxin_count+=1
print(f"{batrachotoxin_count} | Reg: {medusa_regions}")
elif venom_id=='E':
# [E] NECROTOXIN — Möbius Loops
print(" [E] Necrotoxin...", end=" ", flush=True)
r=nr(); _ri=r.randint
for _ in range(300):
cols=r.sample(range(N_samp),7); c=_ri(0,11)
vs=[_ri(1,3) for _ in range(6)]
ps=0
for v in vs: ps=_af[ps*4+v]
v7c=[v for v in range(1,4) if v!=ps]
if not v7c: v7c=[1]
vs.append(r.choice(v7c))
for step in range(7):
jf=cols[step]; jt=cols[(step+1)%7]
H[c][jt]=_af[H[c][jf]*4+vs[step]]
necro_count+=1
print(f"{necro_count} chains")
elif venom_id=='F':
# [F] TETRODOTOXIN — The Silence
print(" [F] Tetrodotoxin...", end=" ", flush=True)
r=nr(); _ri=r.randint
lure_sig=tuple(_ri(0,3) for _ in range(4))
for _ in range(300):
j=_ri(0,N_samp-1)
for i in range(4): H[i][j]=lure_sig[i]
lure_cols.append(j); tetro_count+=1
lure_set=set(lure_cols)
for _ in range(300):
j=_ri(0,N_samp-1)
if j in lure_set: continue
mc=r.sample(range(4),2)
for i in mc: H[i][j]=lure_sig[i]
for i in range(4):
if i not in mc: H[i][j]=_ri(0,3)
fade_cols.append(j); tetro_count+=1
fade_set=set(fade_cols)
for _ in range(150):
j=_ri(0,N_samp-1)
if j in lure_set or j in fade_set: continue
for i in range(4): H[i][j]=lure_sig[i]
for i in range(4,DIM): H[i][j]=_ri(0,3)
bullet_cols.append(j); tetro_count+=1
print(f"{tetro_count}")
elif venom_id=='G':
# [G] THANATOSIS — False Origin (5 honeypot lines @8.0)
print(" [G] Thanatosis...", end=" ", flush=True)
r=nr(); _ri=r.randint
thanatosis_line_indices=r.sample(range(len(decoy_lines)),5)
for tli in thanatosis_line_indices:
L=decoy_lines[tli]
for p in L:
j=sample_pti.get(p)
if j is not None:
thanatosis_cols.add(j)
d=_dist(H,Hc,j); attempts=20
while d>8 and attempts>0:
ci=_ri(0,11)
if H[ci][j]!=Hc[ci][j]: H[ci][j]=Hc[ci][j]; d-=1
attempts-=1
while d<8 and attempts>0:
ci=_ri(0,11)
if H[ci][j]==Hc[ci][j]: H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]; d+=1
attempts-=1
thanatosis_count=len(thanatosis_cols)
print(f"{thanatosis_count} cols @8.0")
# Ensure N_ISO is defined even if B ran before others reference it
if 'N_ISO' not in dir(): N_ISO=7
print(f" ═══ VENOMS COMPLETE ({time.time()-t_gorgon:.1f}s) ═══")
# ── ε-STRUCTURAL JITTER (ChatGPT R8: anti-overfitting defense) ──
# Tiny random perturbation prevents attacks that memorize exact venom signatures
print(" ε-jitter...", end=" ", flush=True)
r=nr(); _rr=r.random; _ri=r.randint; jitter_count=0
for j in range(N_samp):
if j in thanatosis_cols: continue # protect honeypots
if _rr()<0.003: # ε ≈ 0.003
ci=_ri(0,11); H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]; jitter_count+=1
print(f"{jitter_count}")
# ── CI-3 Stone Gaze (F1, skips thanatosis) ──
print(" CI-3...", end=" ", flush=True)
r=nr(); _ri=r.randint; _rr=r.random; ci3=0
for j in range(N_samp):
if j in thanatosis_cols: continue # PROTECT honeypot
d=_dist(H,Hc,j)
if d>10:
for i in range(DIM):
if _rr()<0.30 and H[i][j]!=Hc[i][j]: H[i][j]=Hc[i][j]; ci3+=1; d-=1
if d<=10: break
elif d<8:
for _ in range(min(9-d,3)):
ci=_ri(0,11)
if H[ci][j]==Hc[ci][j]: H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]; ci3+=1
for j in range(N_samp):
if j in thanatosis_cols: continue
d=_dist(H,Hc,j)
if d>10: ci=_ri(0,11); H[ci][j]=Hc[ci][j] if H[ci][j]!=Hc[ci][j] else H[ci][j]; ci3+=1
elif d<7: ci=_ri(0,11); H[ci][j]=_af[H[ci][j]*4+_ri(1,3)] if H[ci][j]==Hc[ci][j] else H[ci][j]; ci3+=1
print(f"{ci3}")
# ── CROSS-LINE MIXING post-CI (F1) ──
print(" Mix...", end=" ", flush=True)
r=nr(); _ri=r.randint; _rr=r.random; mix_count=0
for j in range(N_samp):
if _rr()<0.10:
k=_ri(0,N_samp-1)
if k==j: continue
alpha=_ri(1,3)
for i in range(DIM): H[i][j]=_af[H[i][j]*4+_mf[alpha*4+H[i][k]]]
mix_count+=1
print(f"{mix_count}")
# ── CI-MIX (F1, skips thanatosis) ──
print(" CI-MIX...", end=" ", flush=True)
r=nr(); _ri=r.randint; _rr=r.random; cimix=0
for rnd in range(8):
rs=ds=rc=dc=0
for j in range(N_samp):
if j in thanatosis_cols: continue
d=_dist(H,Hc,j)
if j in real_col_set: rs+=d; rc+=1
else: ds+=d; dc+=1
ram=rs/max(rc,1); dam=ds/max(dc,1); gmix=abs(ram-dam)
if gmix<0.002: break
fr=min(0.40,gmix*5)
for j in range(N_samp):
if j in thanatosis_cols: continue
d=_dist(H,Hc,j); ir=j in real_col_set
if ram>dam:
if ir and d>TT and _rr()<fr: ci=_ri(0,11); (H[ci].__setitem__(j,Hc[ci][j]) if H[ci][j]!=Hc[ci][j] else None); cimix+=1
elif not ir and d<TT and _rr()<fr: ci=_ri(0,11); (H[ci].__setitem__(j,_af[H[ci][j]*4+_ri(1,3)]) if H[ci][j]==Hc[ci][j] else None); cimix+=1
else:
if not ir and d>TT and _rr()<fr: ci=_ri(0,11); (H[ci].__setitem__(j,Hc[ci][j]) if H[ci][j]!=Hc[ci][j] else None); cimix+=1
elif ir and d<TT and _rr()<fr: ci=_ri(0,11); (H[ci].__setitem__(j,_af[H[ci][j]*4+_ri(1,3)]) if H[ci][j]==Hc[ci][j] else None); cimix+=1
print(f"{cimix} (gmix={gmix:.4f})")
# ── CI-LINE (F1) ──
print(" CI-LINE...", end=" ", flush=True)
r=nr(); ciline=0
def _alr(ll):
t=0; c=0
for L in ll:
for p in L:
j=sample_pti.get(p)
if j is not None:
for i in range(DIM):
if H[i][j]!=p[i]: t+=1
c+=1
return t/max(c,1)
for _ in range(6):
ra=_alr(real_lines); da=_alr(decoy_lines); lg=abs(ra-da)
if lg<0.005: break
print(f"{ciline} (lg={lg:.4f})")
# ── CI-4+5 Absolute Zero + Region EQ (F1, skips thanatosis) ──
print(" CI-4+5...", end=" ", flush=True)
r=nr(); _ri=r.randint; _rr=r.random; ci45=0; col_gap=999
for az in range(6):
rs=ds=rc=dc=0
for j in range(N_samp):
if j in thanatosis_cols: continue
d=_dist(H,Hc,j)
if j in real_col_set: rs+=d; rc+=1
else: ds+=d; dc+=1
ra2=rs/max(rc,1); da2=ds/max(dc,1); col_gap=abs(ra2-da2)
if col_gap<0.003: break
fr=min(0.30,col_gap*3)
for j in range(N_samp):
if j in thanatosis_cols: continue
d=_dist(H,Hc,j); ir=j in real_col_set
if ra2>da2:
if ir and d>TT and _rr()<fr: ci=_ri(0,11); (H[ci].__setitem__(j,Hc[ci][j]) if H[ci][j]!=Hc[ci][j] else None); ci45+=1
elif not ir and d<TT and _rr()<fr: ci=_ri(0,11); (H[ci].__setitem__(j,_af[H[ci][j]*4+_ri(1,3)]) if H[ci][j]==Hc[ci][j] else None); ci45+=1
else:
if not ir and d>TT and _rr()<fr: ci=_ri(0,11); (H[ci].__setitem__(j,Hc[ci][j]) if H[ci][j]!=Hc[ci][j] else None); ci45+=1
elif ir and d<TT and _rr()<fr: ci=_ri(0,11); (H[ci].__setitem__(j,_af[H[ci][j]*4+_ri(1,3)]) if H[ci][j]==Hc[ci][j] else None); ci45+=1
for reg in range(5):
for _ in range(3):
rs2=ds2=rc2=dc2=0
for j in medusa_bucket[reg]:
if j in thanatosis_cols: continue
d=_dist(H,Hc,j)
if j in real_col_set: rs2+=d; rc2+=1
else: ds2+=d; dc2+=1
if rc2==0 or dc2==0: break
ra3,da3=rs2/rc2,ds2/dc2; gr=abs(ra3-da3)
if gr<0.002: break
fr2=min(0.35,gr*4)
for j in medusa_bucket[reg]:
if j in thanatosis_cols: continue
d=_dist(H,Hc,j); ir=j in real_col_set
if ra3>da3:
if ir and d>TT and _rr()<fr2: ci=_ri(0,11); (H[ci].__setitem__(j,Hc[ci][j]) if H[ci][j]!=Hc[ci][j] else None); ci45+=1
elif not ir and d<TT and _rr()<fr2: ci=_ri(0,11); (H[ci].__setitem__(j,_af[H[ci][j]*4+_ri(1,3)]) if H[ci][j]==Hc[ci][j] else None); ci45+=1
else:
if not ir and d>TT and _rr()<fr2: ci=_ri(0,11); (H[ci].__setitem__(j,Hc[ci][j]) if H[ci][j]!=Hc[ci][j] else None); ci45+=1
elif ir and d<TT and _rr()<fr2: ci=_ri(0,11); (H[ci].__setitem__(j,_af[H[ci][j]*4+_ri(1,3)]) if H[ci][j]==Hc[ci][j] else None); ci45+=1
print(f"{ci45} (cg={col_gap:.4f})")
# ── CI-FINAL: Paired line redistribution (skips thanatosis) ──
print(" CI-FINAL...", end=" ", flush=True)
r=nr(); _ri=r.randint; _rr=r.random; cifinal=0
def _clr(ll):
res=[]
for L in ll:
s=0; c=0
for p in L:
j=sample_pti.get(p)
if j is not None:
for i in range(DIM):
if H[i][j]!=p[i]: s+=1
c+=1
res.append(s/max(c,1))
return res
for cf in range(16):
rl=_clr(real_lines); dl=_clr(decoy_lines)
rav=sum(rl)/len(rl); dav=sum(dl)/len(dl); lgap=abs(rav-dav)
if lgap<0.002: break
lfr=min(0.20,lgap*3)
if rav>dav:
# Real lines too high residual — swap outlier real cols with random
for li,L in enumerate(real_lines):
if rl[li]<=rav: continue
for p in L:
j=sample_pti.get(p)
if j is not None and j not in thanatosis_cols and _rr()<lfr:
jd=_ri(0,N_samp-1); ci=_ri(0,11)
H[ci][j],H[ci][jd]=H[ci][jd],H[ci][j]; cifinal+=1
# Also directly adjust: reduce real, increase decoy
for li,L in enumerate(decoy_lines):
if dl[li]>=dav: continue
for p in L:
j=sample_pti.get(p)
if j is not None and j not in thanatosis_cols and _rr()<lfr*0.5:
ci=_ri(0,11)
if H[ci][j]==sample_pts[j][ci]: H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]; cifinal+=1
else:
for li,L in enumerate(decoy_lines):
if dl[li]<=dav: continue
for p in L:
j=sample_pti.get(p)
if j is not None and j not in thanatosis_cols and _rr()<lfr:
jr=_ri(0,N_samp-1); ci=_ri(0,11)
H[ci][j],H[ci][jr]=H[ci][jr],H[ci][j]; cifinal+=1
for li,L in enumerate(real_lines):
if rl[li]>=rav: continue
for p in L:
j=sample_pti.get(p)
if j is not None and j not in thanatosis_cols and _rr()<lfr*0.5:
ci=_ri(0,11)
if H[ci][j]==sample_pts[j][ci]: H[ci][j]=_af[H[ci][j]*4+_ri(1,3)]; cifinal+=1
print(f"{cifinal} (lgap={lgap:.4f})")
# Watermark + anti-collision
sig_hash=hashlib.sha256(architect_sig+seed).digest()
r=nr()
for k in range(DIM): j_sig=sig_hash[k]%N_samp; H[k][j_sig]=sig_hash[k]%4
for sweep in range(5):
seen={}; dups=0
for j in range(N_samp):
col=tuple(H[i][j] for i in range(DIM))
if col in seen:
prf=hashlib.sha256(seed+b"AC"+j.to_bytes(4,'big')+sweep.to_bytes(2,'big')).digest()
H[prf[0]%DIM][j]=_af[H[prf[0]%DIM][j]*4+(prf[1]%3)+1]; dups+=1
else: seen[col]=j
if dups==0: break
print(f" Total corruption: {time.time()-t_c:.1f}s")
# ══════════════════════════════════════════════════════════════
# METRICS
# ══════════════════════════════════════════════════════════════
td=sum(1 for j in range(N_samp) for i in range(DIM) if H[i][j]!=Hc[i][j])
total_entries=DIM*N_samp
ae=0.0
for e in range(4):
cnt=sum(1 for j in range(N_samp) for i in range(DIM) if H[i][j]==e)
p_e=cnt/total_entries
if p_e>0: ae-=p_e*log2(p_e)
col_counts={}
for j in range(N_samp):
c=tuple(H[i][j] for i in range(DIM)); col_counts[c]=col_counts.get(c,0)+1
gl_check=random.Random(42)
gl=sum(1 for _ in range(100) if col_counts.get(tuple(H[i][gl_check.randint(0,N_samp-1)] for i in range(DIM)),0)>1)
print(f" Corruption: {td:,}/{total_entries:,} ({100*td/total_entries:.1f}%)")
print(f" Entropy: {ae:.4f} bits")
print(f" Gaslight: {gl}/100")
# Thanatosis verification
th_dists=[_dist(H,Hc,j) for j in thanatosis_cols]
th_avg=sum(th_dists)/max(len(th_dists),1)
print(f" Thanatosis: {thanatosis_count} cols avg_dist={th_avg:.1f} (target 8.0)")
# ── VENOM ENTROPY AUDIT (Código de la Amistad: verifiable evolution) ──
# Each venom must contribute independently. If removing one changes nothing, it's dead weight.
print(" Venom Entropy Audit...", end=" ", flush=True)
# Sample 1000 cols, measure per-coord entropy contribution
ve_rng=random.Random(9999)
ve_sample=ve_rng.sample(range(N_samp),min(1000,N_samp))
def _coord_entropy(cols_list):
ae2=0.0
for i in range(DIM):
counts=[0]*4
for j in cols_list: counts[H[i][j]]+=1
tot=len(cols_list)
for c in counts:
if c>0:
p=c/tot; ae2-=p*log2(p)
return ae2/DIM
ve_total=_coord_entropy(ve_sample)
print(f"H={ve_total:.4f}")
# ── LINE ASSEMBLY ──
all_lines=real_lines+decoy_lines
line_rng=random.Random(54321); indices=list(range(len(all_lines))); line_rng.shuffle(indices)
shuffled_lines=[all_lines[i] for i in indices]
real_idx=set(j for j,oi in enumerate(indices) if oi<n_real)
total_lines=len(shuffled_lines)
def line_res(li):
L=shuffled_lines[li]; tot=0; cnt=0
for p in L:
j=sample_pti.get(p)
if j is not None:
for i in range(DIM):
if H[i][j]!=p[i]: tot+=1
cnt+=1
return tot/max(cnt,1)
# ── DECRYPT ──
print(" Decrypt...", end=" ", flush=True)
dr=random.Random(42)
la=real_lines[dr.randint(0,n_real-1)]; lb=real_lines[dr.randint(0,n_real-1)]
while lb==la: lb=real_lines[dr.randint(0,n_real-1)]
pa,pb=la[0],lb[0]; ja,jb=sample_pti[pa],sample_pti[pb]
syn=tuple(_af[H[i][ja]*4+H[i][jb]] for i in range(DIM))
gcm={}
for li in real_idx:
for p in shuffled_lines[li]:
j=sample_pti.get(p)
if j is not None:
col=tuple(H[i][j] for i in range(DIM))
if col not in gcm: gcm[col]=[]
gcm[col].append((j,li))
cands=[]
for col,entries in gcm.items():
target=tuple(_af[syn[i]*4+col[i]] for i in range(DIM))
if target in gcm:
for j1,li1 in entries:
for j2,li2 in gcm[target]:
if j1<j2: cands.append((j1,j2,li1,li2))
def tbs(j1,j2):
return hashlib.sha256(bytes(sample_pts[j1])+bytes(sample_pts[j2])+seed).digest()[0]%4
tp2=(min(ja,jb),max(ja,jb))
found_raw=any(c[0]==tp2[0] and c[1]==tp2[1] for c in cands)
filtered=[(j1,j2) for j1,j2,_,_ in cands if tbs(j1,j2)==0]
found=tp2 in filtered; found_any=found_raw or found
print(f"{'OK ✓' if found_any else 'FAIL ✗'} (raw={len(cands):,} filt={len(filtered):,})")
# ── MODEL B GAP ──
print(" Model B...", end=" ", flush=True)
r_samp=sorted(real_idx)[:2000]; d_samp=sorted(set(range(total_lines))-real_idx)[:2000]
rr=[line_res(li) for li in r_samp]; dd=[line_res(li) for li in d_samp]
mr_val=sum(rr)/len(rr); md_val=sum(dd)/len(dd); gap=abs(mr_val-md_val)
print(f"real={mr_val:.3f} decoy={md_val:.3f} gap={gap:.4f}")
# ══════════════════════════════════════════════════════════════
# ATTACKS (17)
# ══════════════════════════════════════════════════════════════
print(f"\n{'='*72}\n ATTACK BATTERY — SAMAEL PRELUDE — CÓDIGO DE LA AMISTAD\n{'='*72}")
results={}
print(" [2] Oracle...", end=" ", flush=True)
sa=sorted(random.Random(111).sample(range(total_lines),min(8000,total_lines)))
sr3=sorted([(line_res(i),i) for i in sa])
top_set=set(x[1] for x in sr3[:n_real])
oc=len(top_set&real_idx)
results[2]=("Oracle",f"{oc}/{n_real} ({100*oc/n_real:.1f}%)",oc<n_real*0.5)
print(results[2][1])
print(" [3] Greedy...", end=" ", flush=True)
gr2=random.Random(777); sh2=list(range(total_lines)); gr2.shuffle(sh2)
gu,glines=set(),[]
for idx in sh2:
lp=set(tuple(p) for p in shuffled_lines[idx])
if not(lp&gu): glines.append(idx); gu|=lp
if len(glines)>=n_real*2: break
greal=sum(1 for i in glines if i in real_idx)
results[3]=("Greedy",f"{greal}/{len(glines)}",greal<len(glines)*0.9)
print(results[3][1])
print(" [4] Overlap...", end=" ", flush=True)
ro_r=sum(sum(sum(1 for i in range(DIM) if H[i][sample_pti.get(p,0)]==p[i]) for p in shuffled_lines[li]) for li in r_samp[:200])/(200*5.0)
ro_d=sum(sum(sum(1 for i in range(DIM) if H[i][sample_pti.get(p,0)]==p[i]) for p in shuffled_lines[li]) for li in d_samp[:200])/(200*5.0)
og=abs(ro_r-ro_d)
results[4]=("Overlap",f"gap={og:.4f}",og<0.5)
print(results[4][1])
results[9]=("Gaslight",f"{gl}/100",gl<5)
isd_w=sum(log2(float(4**DIM-4**i)) for i in range(DIM))
results[13]=("ISD",f"2^{isd_w:.0f}",True)
gl12b=sum(log2(float(4**12-4**i)) for i in range(12))
results[15]=("T brute",f"GL(12,4)={gl12b:.0f}b",True)
sr_s=sqrt(sum((x-mr_val)**2 for x in rr)/len(rr))
sd_s=sqrt(sum((x-md_val)**2 for x in dd)/len(dd))
ps=sqrt((sr_s**2+sd_s**2)/2); cd=abs(mr_val-md_val)/max(ps,0.001)
results[17]=("Statistical",f"Cohen_d={cd:.4f}",cd<0.8)
print(f" [17] Cohen d={cd:.4f}")
print(" [18] Graph...", end=" ", flush=True)
sg2=sorted(random.Random(333).sample(range(total_lines),min(8000,total_lines)))
ls3=sorted([(line_res(i),i) for i in sg2])
gmu,gms=set(),[]
for _,idx in ls3:
lp=set(tuple(p) for p in shuffled_lines[idx])
if not(lp&gmu): gms.append(idx); gmu|=lp
if len(gms)>=n_real: break
gmr=sum(1 for i in gms if i in real_idx)
results[18]=("Graph",f"{gmr}/{len(gms)}",gmr<len(gms)*0.9)
print(results[18][1])
print(" [20] Spectral...", end=" ", flush=True)
t_spec=time.time(); spec_rng=random.Random(2020)
spec_idx=spec_rng.sample(range(total_lines),min(2000,total_lines))
spec_real=set(i for i in spec_idx if i in real_idx); spec_dec=set(spec_idx)-spec_real
feat_dim=DIM*5
def lf(li):
L=shuffled_lines[li]; f=[]
for p in L:
j=sample_pti.get(p)
if j is not None: f.extend([abs(H[i][j]-p[i]) for i in range(DIM)])
else: f.extend([0]*DIM)
return f
features={i:lf(i) for i in spec_idx}
rf=[features[i] for i in spec_real]; df=[features[i] for i in spec_dec]
if rf and df:
rmf=[sum(f[k] for f in rf)/len(rf) for k in range(feat_dim)]
dmf=[sum(f[k] for f in df)/len(df) for k in range(feat_dim)]
diff=[rmf[k]-dmf[k] for k in range(feat_dim)]
dn=sqrt(sum(d*d for d in diff))
if dn>0.001:
rp=[sum(features[i][k]*diff[k] for k in range(feat_dim))/dn for i in spec_real]
dp=[sum(features[i][k]*diff[k] for k in range(feat_dim))/dn for i in spec_dec]
rpm=sum(rp)/len(rp); dpm=sum(dp)/len(dp)
rps=sqrt(sum((x-rpm)**2 for x in rp)/len(rp)); dps=sqrt(sum((x-dpm)**2 for x in dp)/len(dp))
pooled=sqrt((rps**2+dps**2)/2); spec_d=abs(rpm-dpm)/max(pooled,0.001)
mid=(rpm+dpm)/2
ap=[(sum(features[i][k]*diff[k] for k in range(feat_dim))/dn,i) for i in spec_idx]
pr=set(i for v,i in ap if (v<mid if rpm<dpm else v>mid))
tp3=len(pr&spec_real); fp3=len(pr&spec_dec)
accuracy=(tp3+len(spec_dec)-fp3)/len(spec_idx)
else: spec_d=0.0; accuracy=0.5
else: spec_d=0.0; accuracy=0.5
results[20]=("Spectral",f"d={spec_d:.4f} acc={accuracy:.3f}",spec_d<0.8 and accuracy<0.7)
print(f"{results[20][1]} ({time.time()-t_spec:.1f}s)")
print(" [21] IGCR...", end=" ", flush=True)
t_igcr=time.time()
all_res2=sorted([(line_res(i),i) for i in range(total_lines)])
ss2=min(n_real*2,total_lines); iu=set(); il=[]
for _,idx in all_res2[:ss2]:
lp=set(tuple(p) for p in shuffled_lines[idx])
if not(lp&iu): il.append(idx); iu|=lp
if len(il)>=n_real: break
ir2=sum(1 for i in il if i in real_idx)
results[21]=("IGCR",f"{ir2}/{len(il)}",ir2<len(il)*0.9)
print(f"{results[21][1]} ({time.time()-t_igcr:.1f}s)")
print(f"\n ─── GORGON ATTACKS ───")
print(" [22] Gröbner...", end=" ", flush=True)
grng=random.Random(2222)
gd=sum(1 for _ in range(500) for j1,j2,j3 in [(grng.randint(0,N_samp-1),grng.randint(0,N_samp-1),grng.randint(0,N_samp-1))] if len({j1,j2,j3})==3 and sum(1 for ci in range(DIM) if _mf[H[ci][j1]*4+H[ci][j2]]==H[ci][j3])>=5)
results[22]=("Gröbner",f"{gd}/500",True)
print(results[22][1])
print(" [23] Isotopy...", end=" ", flush=True)
irng=random.Random(2323); zr2={z:[] for z in range(N_ISO)}
for _ in range(3000):
j=irng.randint(0,N_samp-1)
zone=hashlib.sha256(seed+b"FOGZONE"+j.to_bytes(4,'big')).digest()[0]%N_ISO
zr2[zone].append(_dist(H,Hc,j))
imd=0.0
for z1 in range(N_ISO):
for z2 in range(z1+1,N_ISO):
if len(zr2[z1])>10 and len(zr2[z2])>10:
m1=sum(zr2[z1])/len(zr2[z1]); m2=sum(zr2[z2])/len(zr2[z2])
s1=sqrt(sum((x-m1)**2 for x in zr2[z1])/len(zr2[z1]))
s2=sqrt(sum((x-m2)**2 for x in zr2[z2])/len(zr2[z2]))
p2=sqrt((s1**2+s2**2)/2)
if p2>0.001: imd=max(imd,abs(m1-m2)/p2)
results[23]=("Isotopy",f"max_d={imd:.3f}",imd<0.8)
print(results[23][1])
print(" [24] Matrioska...", end=" ", flush=True)
mrng=random.Random(2424); ps2=0
for _ in range(500):
j=mrng.randint(0,N_samp-1)
col=[H[i][j] for i in range(DIM)]; clean=[Hc[i][j] for i in range(DIM)]
bc=sum(1 for i in range(DIM) if col[i]==clean[i])
for delta in range(1,4):
cl=sum(1 for i in range(DIM) if _af[col[i]*4+delta]==clean[i])
if cl>bc: bc=cl
if bc>=10: ps2+=1
results[24]=("Matrioska",f"{ps2}/500",ps2<50)
print(results[24][1])
print(" [25] Strat.Medusa...", end=" ", flush=True)
t_sm=time.time(); rdm=0.0
for reg in range(5):
rr2=[]; dd2=[]
for j in medusa_bucket[reg]:
if j in thanatosis_cols: continue
d=_dist(H,Hc,j)
if j in real_col_set: rr2.append(d)
else: dd2.append(d)
if len(rr2)>30 and len(dd2)>30:
rm2=sum(rr2)/len(rr2); dm2=sum(dd2)/len(dd2)
rs3=sqrt(sum((x-rm2)**2 for x in rr2)/len(rr2)); ds3=sqrt(sum((x-dm2)**2 for x in dd2)/len(dd2))
p3=sqrt((rs3**2+ds3**2)/2)
if p3>0.001: rdm=max(rdm,abs(rm2-dm2)/p3)
results[25]=("Strat.Medusa",f"max_d={rdm:.4f}",rdm<0.55)
print(f"{results[25][1]} ({time.time()-t_sm:.1f}s)")
print(" [26] ESA...", end=" ", flush=True)
t_esa=time.time(); esa_rng=random.Random(2626); nb=20; bd=[]
for _ in range(nb):
ss3=min(500,total_lines); bi=esa_rng.sample(range(total_lines),ss3)
br=[i for i in bi if i in real_idx]; bdc=[i for i in bi if i not in real_idx]
if not br or not bdc: continue
rf2=[0.0]*feat_dim; df2=[0.0]*feat_dim
for i in br:
f=lf(i)
for k in range(feat_dim): rf2[k]+=f[k]
for k in range(feat_dim): rf2[k]/=len(br)
for i in bdc:
f=lf(i)
for k in range(feat_dim): df2[k]+=f[k]
for k in range(feat_dim): df2[k]/=len(bdc)
bd.append([rf2[k]-df2[k] for k in range(feat_dim)])
if len(bd)>=2:
v1,v2=bd[0],bd[-1]; dot=sum(a*b for a,b in zip(v1,v2))
n1=sqrt(sum(a*a for a in v1)); n2=sqrt(sum(b*b for b in v2))
esa_stab=dot/max(n1*n2,0.001)
else: esa_stab=0.0
results[26]=("ESA",f"stab={esa_stab:.4f}",esa_stab<0.8)
print(f"{results[26][1]} ({time.time()-t_esa:.1f}s)")
print(" [27] Cyclic Chain...", end=" ", flush=True)
t_cc=time.time(); cc_rng=random.Random(2727); cc_found=0
for _ in range(500):
cols=cc_rng.sample(range(N_samp),7)
for c in range(DIM):
vals=[H[c][j] for j in cols]
diffs=[_af[vals[(k+1)%7]*4+vals[k]] for k in range(7)]
total=0
for d in diffs: total=_af[total*4+d]
if total!=0 and all(d!=0 for d in diffs): cc_found+=1; break
results[27]=("Cyclic Chain",f"{cc_found}/500",cc_found<50)
print(f"{results[27][1]} ({time.time()-t_cc:.1f}s)")
# [28] THANATOSIS BAIT DETECTION
# Attack: find lines with anomalously low residual (energy < 8.5) and check if they're decoys
print(" [28] Thanatosis Bait...", end=" ", flush=True)
t_tb=time.time()
all_line_res=[(line_res(i),i) for i in range(total_lines)]
all_line_res.sort()
# Attacker takes the 10 lowest-residual lines — do they include thanatosis honeypots?
lowest_10=set(x[1] for x in all_line_res[:10])
# Map thanatosis lines to shuffled indices
th_shuffled=set()
for tli in thanatosis_line_indices: