-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNormal_function.py
50 lines (38 loc) · 1.47 KB
/
Normal_function.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
from Normal_gates import NormalGate, AndGate, OrGate, XorGate, NormalCircuit
# ai bi ci true---|/////| (this gate is to ensure the input of a Circuit is always
# | | | 3| AND |--------------+ a Circuit or Gate, not raw number)
# o---+---+-----------|\\\\\| |
# | | | +---->|/////|
# o---+---+--->|/////| 5| XOR |---->c(i+1)
# | | | 1| XOR |-----+ +---->|\\\\\|
# | | o--->|\\\\\| +---->|/////| |
# | | | 4| AND |---+
# | o---+--->|/////| +---->|\\\\\|
# | | | 2| XOR |-----+
# | | o--->|\\\\\|
#
def bit_compare(a, b, c):
gate1 = XorGate(a, c)
gate2 = XorGate(b, c)
gate3 = AndGate(a, 1)
gate4 = AndGate()
gate5 = XorGate()
circuit = NormalCircuit(gate5,
NormalCircuit(gate3, None, None),
NormalCircuit(gate4,
NormalCircuit(gate2, None, None),
NormalCircuit(gate1, None, None)))
output = circuit.calc()
return output
byte_array1 = [1, 1, 1, 1]
byte_array2 = [1, 0, 1, 0]
c = 0
print(bit_compare(1, 1, 0))
for _ in range(len(byte_array1)):
a = byte_array1[_]
b = byte_array2[_]
c = bit_compare(a, b, c)
if c:
print("a is greater than b")
else:
print("a is less than or equal to b")