代码拉取完成,页面将自动刷新
import numpy as np
import random
import pandas as pd
def simulate_attacker_guesses(num_guesses, grid_size, min_selections, max_selections, restricted_cells, bias_points):
"""
Simulate an attacker guessing passwords considering bias points influenced by image elements.
:param num_guesses: Number of guesses to simulate
:param grid_size: Size of the grid (number of rows and columns)
:param min_selections: Minimum number of cells to be selected for a password
:param max_selections: Maximum number of cells that can be selected for a password
:param restricted_cells: List of cells that cannot be selected
:param bias_points: Points that are more likely to be chosen due to image influence
:return: List of guessed passwords
"""
guesses = []
# Create a probability distribution favoring the bias points
total_points = grid_size * grid_size
base_prob = 1 / total_points
bias_prob_increase = 0.1 # How much more likely are we to choose a bias point
probabilities = np.full((grid_size, grid_size), base_prob)
for point in bias_points:
probabilities[point] += bias_prob_increase
probabilities /= probabilities.sum() # Normalize to sum to 1
for _ in range(num_guesses):
num_selections = random.randint(min_selections, max_selections)
guess = []
while len(guess) < num_selections:
flat_index = np.random.choice(total_points, p=probabilities.flatten())
row, col = divmod(flat_index, grid_size)
cell = (row, col)
if cell not in restricted_cells and cell not in guess:
guess.append(cell)
guesses.append(guess)
return guesses
# Update these variables based on the actual bias points from your image
bias_points = [(1, 2), (2, 3), (4, 5), (5, 6)] # Replace with actual bias points
grid_size = 8
min_selections = 4
max_selections = 10
restricted_cells = [(0, 0), (7, 0), (0, 7), (7, 7), (3, 3), (3, 4), (4, 3), (4, 4)]
num_guesses = 1100
# Simulate attacker guesses
attacker_guesses = simulate_attacker_guesses(num_guesses, grid_size, min_selections, max_selections, restricted_cells,
bias_points)
# Save the guesses to an Excel file
df_guesses = pd.DataFrame({'Guessed Password': attacker_guesses})
df_guesses.to_excel('attacker_guesses.xlsx', index=False)
print("Attacker guesses have been saved to 'attacker_guesses.xlsx'.")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。