Skip to content

Commit

Permalink
Update rsa
Browse files Browse the repository at this point in the history
  • Loading branch information
ehoneahobed authored Sep 17, 2022
1 parent 71c2ad4 commit 1e65048
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions rsa
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
#!/usr/bin/python3
import sys


def factorize(num):
""" Generate 2 factors for a given number"""
factor1 = 2
while (num % factor1):
if (factor1 <= num):
factor1 += 1

factor2 = num // factor1
return (factor2, factor1)


if len(sys.argv) != 2:
sys.exit(f"Wrong usage: {sys.argv[0]} <file_path>")

filename = sys.argv[1]

file = open(filename, 'r')
lines = file.readlines()

for line in lines:
num = int(line.rstrip())
factor2, factor1 = factorize(num)
print(f"{num} = {factor2} * {factor1}")
#!/usr/bin/env python3
""" Factor numbers """
from sys import argv
from math import sqrt


def open_read_file(file_name):
"""read from file
add to array
"""
with open(file_name, encoding="utf-8") as file:
lines = file.readlines()
number_to_factor = []
for line in lines:
number_to_factor.append(int(line))
return number_to_factor


def find_and_times(n):
"""factor each
n given
"""
for i in range(2, n):
if n == ((n // i) * i):
print("{}={}*{}".format(n, (n // i), i))
break


def fac_list(ls):
"""factor each
num in ls
"""
for i in ls:
find_and_times(i)


if len(argv) == 2:
fac_list(open_read_file(argv[1]))

0 comments on commit 1e65048

Please sign in to comment.