I have a problem where the RSA implementation doesn't work in a specific line of code:
def chooseKeys():
"""
Selects two random prime numbers from a list of prime numbers which has
values that go up to 100k. It creates a text file and stores the two
numbers there where they can be used later. Using the prime numbers,
it also computes and stores the public and private keys in two separate
files.
"""
# choose two random numbers within the range of lines where
# the prime numbers are not too small and not too big
rand1 = random.randint(100, 300)
rand2 = random.randint(100, 300)
# store the txt file of prime numbers in a python list
fo = open('primes-to-100k.txt', 'r')
lines = fo.read().splitlines()
fo.close()
# store our prime numbers in these variables
prime1 = int(lines[rand1])
prime2 = int(lines[rand2])
# compute n, totient, e
n = prime1 * prime2
totient = (prime1 - 1) * (prime2 - 1)
e = chooseE(totient)
# compute d, 1 < d < totient such that ed = 1 (mod totient)
# e and d are inverses (mod totient)
gcd, x, y = xgcd(e, totient)
# make sure d is positive
if (x < 0):
d = x + totient
else:
d = x
# write the public keys n and e to a file
f_public = open('public_keys.txt', 'w')
f_public.write(str(n) + '\n')
f_public.write(str(e) + '\n')
f_public.close()
f_private = open('private_keys.txt', 'w')
f_private.write(str(n) + '\n')
f_private.write(str(d) + '\n')
f_private.close()
the problem here is this line:
# store the txt file of prime numbers in a python list
fo = open('primes-to-100k.txt', 'r')
lines = fo.read().splitlines()
fo.close()
it always says Exception has occurred: FileNotFoundError
[Errno 2] No such file or directory: 'primes-to-100k.txt'
so for that I tried to use the path for the file, didn't work, tried to use the relative path, that also didn't work, any solution for thi