-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsa
executable file
·46 lines (38 loc) · 1.07 KB
/
rsa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python3
from sys import argv
import math
"""gets the first two factors of any number"""
def is_prime(num):
"""checks if a number is prime"""
i = 3
if num % 2 == 0:
return False
while i * i <= num:
if num % i == 0:
return False
i += 2
return True
def factory(num):
"""This factor function gets the factors of a number & prints them out"""
if num % 2 == 0:
i = 2
print("{}={}*{}".format(num, int(num/i), i))
else:
sq = math.sqrt(num)
if sq % 1 == 0:
print("{}={}*{}".format(num, sq, int(num/sq)))
return
sq = int(sq) + 1
for i in range(3, sq, +2):
if num % i == 0:
if is_prime(i):
print("{}={}*{}".format(num, int(num/i), i))
return
def factors(filename):
"""read_file"""
with open(filename, encoding="utf-8") as my_file:
for i in my_file.readlines():
n = int(i)
result = factory(n)
if __name__ == "__main__":
factors(argv[1])