I have a problem with efficiency in python. For several days I now tried to find and test different implementations, but just can't get it to work fast enough.
Task: I have two lists arr and arr2 with 1000000 entries of b'' (resulting of encryption and decryption with keys "00000000" to "00999999") and know have to find a match in those two(DES2 Meet in the Middle). Therefore
if arr[x] == arr2[y]:
return x, y
I think that my solution would work, but its so slow, that its not enough:
def g(x):
for k in range(0, 1000000):
if (arr[x] == arr2[k]):
return k, x
return 0
keypair = 0
for k in range(0, 1000000):
if keypair == 0:
keypair = g(k)
else:
break
The problem is, that the keypair should be found in less than 40 seconds, but e.g. this example takes 1 minute for 1000 of the 1000000 entries.
Now somehow the efficiency has to be improved in certain ways. I tried around with some other solutions, that promised more efficiency e.g. map and numpys solution for arrays, but didn't get any real improvement in speed.
Do you know any smart solutions?