Home > Blockchain >  Why doesn't x**y%z work like pow(x, y, z) if y is negative?
Why doesn't x**y%z work like pow(x, y, z) if y is negative?

Time:01-12

I have these values for x, y and z:

x = 1402709587326125487755933770599785022011554878478352915458023572822263891029946822919389113025226898265
y = -1653150172609560595889587008271025520100868674290063537844119789327420377094035018771640253912456367085
z = 5223965736281209292468836459168070829492174759961935620654434528517414151878323192140113927287012325803

pow(x,y,z) returns 6996453002252837241098775666312149651703153544682991747419581607713 (like it needs to be according to the RSA-assignment)

x**y%z should do the same, but returns 0.0 Can someone explain why? I'm guessing it has something to do with the negative y.

CodePudding user response:

When you compute

x ** y % z

you do it in two steps: (x ** y) % z. The very first step

x ** y

returns floating point fraction which is by far below 5.562684646268003E-309 (which is the minimum possible magnitude for double). So, x ** y == 0.0 and, finally, 0 % z == 0

  •  Tags:  
  • Related