0

I'm doing a mockup of an RSA Key generation, however in my python code I keep getting this traceback

Traceback (most recent call last):

File "main.py", line 88, in <module>

e= random.randint(1, phi_n - 1)

AttributeError: 'builtin_function_or_method' object has no attribute 'randint'
from random import random, randrange, getrandbits, randint

#RSA Key generation
p=10901009301486216783837946716092058424135573374664735347830598196173785586611407261441711670705344256295673923919130212129440261694153470133415776192580387
q=8832596322191268124023251309111139917569700077420384757505252214138594117132436575010876851227478058236456118017778016128118196705270782663559340597535529
n= p * q
phi_n= (p-1) * (q-1)
e= random.randint(1, phi_n - 1)
while((EucAlgo(e,phi_n)) !=1):
  e = random.randint(1, (phi_n-1))
d= ExEucAlgo_modInverse(e,phi_n)
print(f"Kpr={d}")
print(f"Kpub=(n={n}) \n e={e}")

Code can be seen here

3
  • How does your imports look like? Commented Nov 22, 2020 at 15:12
  • from random import random, randrange, getrandbits, randint Commented Nov 22, 2020 at 15:12
  • Does it work when you change random.randint to randint? Commented Nov 22, 2020 at 15:18

3 Answers 3

3

This can occur probably because you have another variable named random or you have not imported it properly.

Try checking your code over to see what else you assigned random to by doing,

print(random, type(random))

You can also try to import it like,

import random as rand
y = rand.randint(1,10) #Use it like this

Since you are directly importing the functions from the module 'random', you don't have to call them like module_name.function_name

from random import random, randrange, getrandbits, randint 
y = randint(1,10) 
Sign up to request clarification or add additional context in comments.

Comments

1

Simply change random.randint to just randint

Comments

-1

It was caused because you have this: from random import random

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.