1 Star 0 Fork 0

wkh/keti-python-rugp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
attacker_guesses.py 2.40 KB
一键复制 编辑 原始数据 按行查看 历史
wkh 提交于 2024-01-26 21:48 . feat: keti python
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'.")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wkhn1/keti-python-rugp.git
git@gitee.com:wkhn1/keti-python-rugp.git
wkhn1
keti-python-rugp
keti-python-rugp
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385