# (iii)# having a collision means# a^{x1} b^{x2} == a^{y1} b^{y2} # with (x1,x2)!==(y1,y2)# taking discrete logarithms dlog_a on both sides givez=var('z')x1+x2*z==y1+y2*z# where z is the requested dlog_a b
5564*z + 7431 == 954*z + 1459
solve_mod(x1+x2*z==y1+y2*z,q)# Beware about the modulus! p-1 would give two solutions for this equation, i.e. additionally 9555).