Skip to content

Commit d9cbe84

Browse files
committed
Lab8
1 parent a624259 commit d9cbe84

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

lab8/solve.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
#!/usr/bin/env python3
2-
3-
import angr,sys
2+
import sys
3+
import claripy
44

55
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
6+
bvs = [claripy.BVS(f'k{i}', 32) for i in range(8)]
7+
solver = claripy.Solver()
8+
9+
for x in bvs:
10+
solver.add(x >= 0)
11+
solver.add(x <= 255)
12+
13+
solver.add(bvs[0] ^ bvs[1] == 0x55)
14+
solver.add(bvs[2] + bvs[3] == 200)
15+
solver.add(bvs[4] * 3 == bvs[5])
16+
solver.add(bvs[6] - bvs[7] == 1)
17+
solver.add(bvs[1] + bvs[2] - bvs[3] == 50)
18+
solver.add(bvs[5] ^ bvs[6] == 0x2A)
19+
20+
for x in bvs:
21+
solver.add(x >= 0x20)
22+
solver.add(x <= 0x7e)
23+
solver.add(x != 0x0a)
824

25+
if solver.satisfiable():
26+
vals = [solver.eval(x, 1)[0] for x in bvs]
27+
solution = bytes(vals)
28+
hex_str = " ".join(f"{v:02x}" for v in vals)
29+
ascii_str = solution.decode('ascii', errors='replace')
30+
sys.stdout.buffer.write(solution)
31+
else:
32+
sys.exit(1)
933

10-
if __name__ == '__main__':
34+
if __name__ == "__main__":
1135
main()

0 commit comments

Comments
 (0)