-
Notifications
You must be signed in to change notification settings - Fork 1
/
slow_rsa
executable file
·46 lines (32 loc) · 1015 Bytes
/
slow_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/env python3
from sys import argv
from math import sqrt
def read_test_file(file_name):
"""Function to read number from file: one number per file"""
with open(file_name, "r", encoding="utf-8") as file:
lines = file.readlines()
number_to_factor = []
for line in lines:
number_to_factor.append(int(line.strip()))
return number_to_factor
def isprime(n):
"""Check if a number is prime."""
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def find_numbers(n):
"""Function to find factors of current number"""
for i in range(1, n):
if n == ((n // i) * i):
if isprime(i) and isprime(n // i):
print("{}={}*{}".format(n, (n // i), i))
break
def factors(ls):
"""Function to iterate between numbers in file"""
for i in ls:
find_numbers(i)
if len(argv) == 2:
factors(read_test_file(argv[1]))