-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssQ_malware_propagation.py
More file actions
39 lines (31 loc) · 976 Bytes
/
ssQ_malware_propagation.py
File metadata and controls
39 lines (31 loc) · 976 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
39
import random
def propagate_malware(network, infected, iterations):
network_size = len(network)
infection_sequence = []
for _ in range(iterations):
new_infections = set()
for node in infected:
# Infect neighbors
for neighbor in network[node]:
if neighbor not in infected:
new_infections.add(neighbor)
infected.update(new_infections)
infection_sequence.append(list(infected))
if len(infected) == network_size:
break
return infection_sequence
# Example network (adjacency list)
network = {
0: [1, 2],
1: [0, 3],
2: [0, 3],
3: [1, 2, 4],
4: [3]
}
# Initial infected nodes
infected = {0}
iterations = 10
# Simulate malware propagation
infection_sequence = propagate_malware(network, infected, iterations)
for step, infected_nodes in enumerate(infection_sequence):
print(f"Step {step + 1}: {infected_nodes}")