So, I am attempting to search a json file using python and am completely stuck. I will probably get ragged for this, but I have nowhere else to turn. I am a python novice and have been unable to find the info I need by searching....
Here is what I am attempting to do: I have a constant, called A1, the same length as X1, but a different value. I wish to divide my constant by each subsequent X1 (located in the json file). When there is a remainder (modulo) of more than 2, I wish to print the X1 value. Basically I am attempting to find the GCD of my constant and every X1, but the gcd will typically only be 1. I only wish to print when the modulo is greater than 1.
Here is my json file:
{
“536723876acbdacbd3344”: {
“X1”: "0x2345678abcdef1”,
“X2”: "0x12345678abcde"
},
“7632948974879abcdabcd”: {
“X1”: "0x1234678abcdef”,
“X2”: "0x12345678abcde"
},
“23847298347233abcdabcd”: {
“X1”: "0x1234678abcddd”,
“X2”: "0x12345678abcde"
}
}
Here is the code I've written so far:
import json
data = json.load(open("test1.json"))
def translate(w):
A1 = int("0xffff123123", 16)
if w in data.values:
X1 = int("w", 16)
if A1%X1 > 2:
print("The modulo is", data.values[X1])
else:
print( "No match")
Any help would be nice. I'm having a hard way finding the information I need by searching. Thank you!