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

2020-04-29 Thread Basic ICT Repairs


New submission from Basic ICT Repairs :

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 
<https://bugs.python.org/issue40446>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2020-04-29 Thread Basic ICT Repairs


Basic ICT Repairs  added the comment:

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

--
type:  -> behavior
versions: +Python 3.7

___
Python tracker 
<https://bugs.python.org/issue40446>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com