-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrsa
executable file
·32 lines (28 loc) · 978 Bytes
/
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
#!/usr/bin/python3
"""
Factorize numbers in a file into a product of two prime numbers
"""
import sys
def factorize():
"""
A function to search file and factorize the given set of numbers into two prime numbers (format n = p*q)
"""
try:
file = sys.argv[1]
with open(file) as f:
for line_number in f:
line_number = int(line_number)
if line_number % 2 == 0:
print("{}={}*{}".format(line_number, line_number // 2, 2))
continue
i = 3
while i < line_number // 2:
if line_number % i == 0:
print("{}={}*{}".format(line_number, line_number // i, i))
break
i = i + 2
if i == (line_number // 2) + 1:
print("{}={}*{}".format(line_number, line_number, 1))
except (IndexError):
pass
factorize()