-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm.py
64 lines (64 loc) · 1.06 KB
/
vm.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
q = 0x1
w = 0x2
e = 0x3
r = 0x4
t = 0x5
y = 0x6
u = 0x7
o = 0x8
p = []
a = open("instructions.bin",'rb').read()
s = a[0]
d = input("Enter the flag: ")
if len(d) != s:
print("Incorrect")
exit()
d = d[:s]
f = []
for g in d:
f.append(ord(g))
i = 1
h = 0
while i < len(a):
j = a[i]
if j == q:
p.append(a[i+1])
i += 2
elif (j == w) and (h < s):
p.append(f[h])
h += 1
i += 1
elif j == e:
l = p.pop()
print(l)
i += 1
elif j == r:
z = p.pop()
x = p.pop()
p.append(z + x)
i += 1
elif j == t:
z = p.pop()
x = p.pop()
p.append(z - x)
i += 1
elif j == y:
z = p.pop()
x = p.pop()
p.append(z * x)
i += 1
elif j == u:
z = p.pop()
x = p.pop()
p.append(z ^ x)
i += 1
elif j == o:
k = p.pop()
if k !=0:
print("Incorrect!")
exit()
i += 1
else:
print("Invalid instruction")
exit()
print("Correct!!")