-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.py
46 lines (36 loc) · 1.2 KB
/
order.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
def main():
# Grabs Input from terminal
firstNumString = input("Enter In the first number: ")
secondNumString = input("Enter In the Second number: ")
#Converts Strings into Hex
firstNum = int(firstNumString, 16)
secondNum = int(secondNumString, 16)
#Array Of all Values we want to XOR
result = []
# Russian Peasant
while secondNum != 0:
if (secondNum % 2 != 0):
#Appends to array
result.append(firstNum)
firstNum = firstNum * 2
secondNum = secondNum // 2
if (secondNum % 2 == 0):
firstNum = firstNum * 2
secondNum = secondNum // 2
# Passes Result array to XOR Helper Function function
n = len(result)
FinalValue = xorOfArray(result, n)
#Returns the Final value, Prints In HEX
print(f'Result = {hex(FinalValue)}')
# XOR Helper Function From: https://www.geeksforgeeks.org/find-xor-of-all-elements-in-an-array/
def xorOfArray(arr, n):
# Resultant variable
xor_arr = 0
# Iterating through every element in
# the array
for i in range(n):
# Find XOR with the result
xor_arr = xor_arr ^ arr[i]
# Return the XOR
return xor_arr
main()