So I am trying to implement the Baby Step Giant Step algorithm to calculate discrete logs. Below is my code:

```
# trying to solve 8576 = 3^x (mod 53047)
p = 53047
a = 3
B = 8576

m = int(math.ceil(math.sqrt(p-1)))

baby = []
giant = []
for j in range(0,m-1):
    baby.append((a**j)%p)

for k in range(0,m-1):
    val = a**(-1)%p
    val2 = val**(k*m)%p
    giant.append((B*val2)%p)
    for i in xrange(len(baby)):
        if giant[k] == baby[k]:
            x = j + m*k

```

I think there is something incorrect with my giant step because I am getting very tiny values as outputs and no matches. The correct answer is x = 1234. Can someone tell me what I am doing wrong?