-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_bmr.py
More file actions
33 lines (30 loc) · 1.15 KB
/
debug_bmr.py
File metadata and controls
33 lines (30 loc) · 1.15 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
from patternanalyzer.plugin_api import BytesView
from patternanalyzer.plugins.binary_matrix_rank import BinaryMatrixRankTest
def inspect_rows(m=8, num_matrices=1):
bits_per_matrix = m * m
total_bytes = (bits_per_matrix * num_matrices) // 8
pattern = (b'\xAA\x55') * (total_bytes // 2)
bv = BytesView(pattern)
bits = bv.bit_view()
# Build rows for first matrix
mat_bits = bits[0:bits_per_matrix]
rows = []
for r in range(m):
row_bits = mat_bits[r*m:(r+1)*m]
val = 0
for bit in row_bits:
val = (val << 1) | (1 if bit else 0)
rows.append((row_bits, val))
return rows, bv, pattern
def main():
m = 8
rows, bv, pattern = inspect_rows(m=m, num_matrices=1)
print("First matrix rows (bits, int, bin):")
for i, (rb, val) in enumerate(rows):
print(f"row {i}: bits={rb} int={val} bin={format(val, '08b')}")
# Run full plugin to show ranks
res = BinaryMatrixRankTest().run(BytesView(pattern * 8), {"matrix_dim": m, "min_matrices": 8})
print("\nFull plugin result p_value:", res.p_value)
print("ranks:", res.metrics.get("ranks"))
if __name__ == '__main__':
main()