-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbirth.py
More file actions
38 lines (29 loc) · 840 Bytes
/
Copy pathbirth.py
File metadata and controls
38 lines (29 loc) · 840 Bytes
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
import random
import math
import matplotlib.pyplot as plt
def birthday_attack_sim(n, max_samples):
seen = set()
collisions = []
probs = []
for d in range(1, max_samples + 1):
value = random.randint(0, n-1)
if value in seen:
collisions.append(1)
else:
collisions.append(0)
seen.add(value)
# probabilidad teórica
prob = 1 - math.exp(-(d*(d-1))/(2*n))
probs.append(prob)
return collisions, probs
# Parámetro (simula tamaño del espacio)
n = 10000
max_samples = 300
collisions, probs = birthday_attack_sim(n, max_samples)
# Graficar
plt.figure()
plt.plot(range(1, max_samples+1), probs)
plt.xlabel("Número de mensajes interceptados")
plt.ylabel("Probabilidad de colisión")
plt.title("Birthday Attack aplicado a RSA")
plt.show()