[New-bugs-announce] [issue40446] pow(a, b, p) where b=int((p-1)/2) spits out gibbrish for big p

Basic ICT Repairs report at bugs.python.org
Thu Apr 30 01:13:20 EDT 2020


New submission from Basic ICT Repairs <basic.ict.repairs at gmail.com>:

Hi, I was calculating Legendre coefficients, and quadratic residues and encountered what I believe to be a bug while using this code: 

for a in range (5):
        exp=int((p-1)/2)
        x=pow(a,exp,p)
        print(x)

If p is an odd prime, then x can have three values [-1,0,-1] - where "-1" refers to p-1. The code works well for reasonably small primes (like 9973). But with big primes(see below), python 3.7 spits out gibberish. Same code in python 2.7 works well.

The problem in python 3.7 can be avoided if exp is defined thusly :  
exp=(p-1)//2

Here is the prime I tried it on : 
p = 101524035174539890485408575671085261788758965189060164484385690801466167356667036677932998889725476582421738788500738738503134356158197247473850273565349249573867251280253564698939768700489401960767007716413932851838937641880157263936985954881657889497583485535527613578457628399173971810541670838543309159139

----------
messages: 367735
nosy: Basic ICT Repairs
priority: normal
severity: normal
status: open
title: pow(a,b,p) where b=int((p-1)/2) spits out gibbrish for big p

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40446>
_______________________________________


More information about the New-bugs-announce mailing list