Prime Factorization of Integers In a Text File

I have a text file with a million integers, each in a new line. For each of these integers, I need to resolve them into their prime factors and exponents. For instance, an integer like 100 should be resolved to 2^2x5^2. I have written the following (poor) code in Java but it just doesn't work as it should. That is, it only reads the first line of the text file and even then, if that integer is an odd number, it doesn't output anything. If it is an even number it only outputs 2^(exponent count). For instance, 100,000,000 returns 2^8. That's it, which is obviously incorrect. Please help. You can write your own version in a language you are familiar with.

package PrimeFact;

import java.math.*;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class PrimeFact{

public static void main(String[] args) throws FileNotFoundException {

try {

File myObj = new File("C:\\Users\\mugah\\Desktop\\hello.txt");

Scanner myReader = new Scanner(myObj);

while (myReader.hasNextLine()) {

String data = myReader.nextLine();

BigInteger number = new BigInteger(data);

int i = 2;

BigInteger newi = BigInteger.valueOf(i);

for (i = 2;

(newi.compareTo(number) == 0 || newi.compareTo(number) == -1); i++) {

int count = 0;

while (number.mod(newi).compareTo(BigInteger.ZERO) == 0) {

number = number.divide(newi);

count++;

}

if (count == 0) continue;

System.out.print(i + "**" + count + ".");

}

}

myReader.close();

} catch (FileNotFoundException e) {

System.out.println("An error occurred.");

e.printStackTrace();

}

}

}

Thank you. That will be all.

πŸ‘︎ 3
πŸ“°︎ r/AskProgramming
πŸ’¬︎
πŸ“…︎ Dec 20 2020
🚨︎ report
Why is weak induction not adequate to enough to prove the every integer greater than 1 has a prime factorization?

Why does strong induction have to be used? I guess I'm having a hard time comprehending when to use either proof style. How do I know if I need the support of all integers up to k, and not just k itself?

πŸ‘︎ 2
πŸ“°︎ r/learnmath
πŸ’¬︎
πŸ‘€︎ u/vitalaffinity
πŸ“…︎ Oct 01 2020
🚨︎ report
RSA-240 factored β€” new integer factorization record lists.gforge.inria.fr/pip…
πŸ‘︎ 373
πŸ“°︎ r/math
πŸ’¬︎
πŸ‘€︎ u/ixfd64
πŸ“…︎ Dec 02 2019
🚨︎ report
Integer factorization using regex (with backreferences) yurichev.com/news/2020062…
πŸ‘︎ 12
πŸ“°︎ r/programming
πŸ’¬︎
πŸ‘€︎ u/ArthurStr0ng
πŸ“…︎ Jun 24 2020
🚨︎ report
Another integer factorization record: RSA-250 mersenneforum.org/showthr…
πŸ‘︎ 38
πŸ“°︎ r/math
πŸ’¬︎
πŸ‘€︎ u/ixfd64
πŸ“…︎ Feb 28 2020
🚨︎ report
Another integer factorization record: RSA-250 mersenneforum.org/showthr…
πŸ‘︎ 45
πŸ“°︎ r/crypto
πŸ’¬︎
πŸ‘€︎ u/ixfd64
πŸ“…︎ Feb 28 2020
🚨︎ report
Integer factorization using regex (with backreferences) yurichev.com/news/2020062…
πŸ‘︎ 5
πŸ“°︎ r/compsci
πŸ’¬︎
πŸ‘€︎ u/ArthurStr0ng
πŸ“…︎ Jun 24 2020
🚨︎ report
RSA-240 factored β€” new integer factorization record lists.gforge.inria.fr/pip…
πŸ‘︎ 61
πŸ“°︎ r/crypto
πŸ’¬︎
πŸ‘€︎ u/ixfd64
πŸ“…︎ Dec 02 2019
🚨︎ report
How many integer factorization algorithm do you know?

I'm solving a challenge where I should factorize this RSA modulus: 85737914105567266183100788624484418711280900241044365214663691835635317826543443063143976809608344194249114776605426568498270124795493303624975384400447493193170052053344543935668697522988211158557528827577595697212680348719528920982604561256941228129998021815001150237085975555109727173275316438372558567696717284749745152486472846839830811719245253674573696720087659513136981252971213162359513063642183176613569345118049896820749640462010343460030817035187074140156234851173597857913872280840739710132748356190524174899883301213563153677520287623128053160275215134435871533438627283575702919158004068417720519960443201925994224772997949913048228261

I tried a lot of different factorization algorithms like Wiener, Fermat, Pollard, etc...

Do you know other ones? What do you suggest to factorize it?

πŸ‘︎ 4
πŸ“°︎ r/cryptography
πŸ’¬︎
πŸ‘€︎ u/Cricco95
πŸ“…︎ Oct 24 2019
🚨︎ report
Solving Subset-Product with INTEGER FACTORIZATION (I'm seeing some similarities to both problems. It would be cool if Factorization was NP-complete!)
import itertools
import operator
from operator import mul
from functools import reduce
from itertools import combinations
import ast

# Solves decision problem that excludes 2_products of (target, 1)
# Only solves positive cases
# Non-repeating integers only


while True:

# Takes input array for Subset-Product

 subset_array = input("Please enter a dictionary: ")
 subset_array = ast.literal_eval(subset_array)


# Takes in target to factor. The loop will find all factors
# The factors will be saved in a list for the next loop.

 target = int(input('enter target to factor, to find K_products: '))

 factors = [];
 for j in range(2, target):
     if target % j == 0:
         factors.append(j)

# Using combinations for subset-product. It will find all combinations
# out of the list factors. A simple "isSubset" comparison will be done
# to decide if the subset of factors exist in subset_array.
# If so a True is returned. 


 for j in range(0, len(factors)):
  for jj in combinations(factors, j):
   if len(jj) > 0:  
    if reduce(mul,jj) == target:
      true = str(set(jj) <= set(subset_array))
      if true == str('True'): 
       print(set(jj) <= set(subset_array), jj)

Output

Please enter a dictionary: 5,4,3,2,1
enter target to factor, to find K_products: 120
True (2, 3, 4, 5)
πŸ‘︎ 3
πŸ“°︎ r/P_vs_NP
πŸ’¬︎
πŸ‘€︎ u/Hope1995x
πŸ“…︎ Mar 17 2020
🚨︎ report
Why Is Integer Factorization Hard? crasmaru.com/post_3.jsp
πŸ‘︎ 23
πŸ“°︎ r/programming
πŸ’¬︎
πŸ‘€︎ u/almaya
πŸ“…︎ Oct 30 2018
🚨︎ report
SOURCE CODE FOR INTEGER FACTORIZATION. This program can factor integers of any arbitrary precision. So public key encryption is null and void as it attacks the basic premise that very large integers cannot be factored in reasonable amounts of time β€’ r/netsec reddit.com/r/netsec/comme…
πŸ‘︎ 62
πŸ’¬︎
πŸ‘€︎ u/breadfag
πŸ“…︎ Jul 26 2017
🚨︎ report
Integer factorization reddit.com/r/MathJokes/co…
πŸ‘︎ 8
πŸ“°︎ r/ScienceJokes
πŸ’¬︎
πŸ‘€︎ u/ixfd64
πŸ“…︎ Apr 22 2019
🚨︎ report
Is there a number field of degree n whose ring of integers is a unique factorization domain? math.stackexchange.com/qu…
πŸ‘︎ 2
πŸ“°︎ r/OnlyMathematics
πŸ’¬︎
πŸ‘€︎ u/xXPhoenix420Xx
πŸ“…︎ Jul 28 2019
🚨︎ report
I made an integer factorization algorithm. How efficient is it?

https://repl.it/@ddotquantum/Integer-factorization

Edit: It returns the prime factorization of x, not the factors of x.

πŸ‘︎ 2
πŸ“°︎ r/learnprogramming
πŸ’¬︎
πŸ‘€︎ u/ddotquantum
πŸ“…︎ Jul 12 2018
🚨︎ report
My journey to finding a faster algorithm for integer factorization. (Long post)

Hi guys I am a senior in high school and I got into math a few years ago. I was fascinated in finding huge prime numbers, and I ran a computer algorithm to find them ( the Lucas-lehmer-Riesel test). Well, I wanted to find out how it works so I taught myself modular arithmetic, which I'm pretty good at.

So I was messing around with different polynomial equations one day trying to find patterns in prime numbers, and I actually managed to independently discover Fermat's factoring method by looking at functions of the form x^2 -c^2 for constant c and finding a pattern in their factors. So I found an algorithm to put numbers in this form, and that is how I independently discovered Fermat's factoring method. From then on I became interested in factoring algorithms after I discovered no fast ones exist for general numbers.

As much as I tried, I could not get myself to understand the newer factoring algorthms- quadratic sieve, number field sieve, much to my frustration. So I sought out my own methods that high school me could understand.

I came across the method I have been researching by looking at residues of fermat's little theorem. My thought was that if fermat's little theorem could determine a number to be prime, it could determine the factors as well, and the factors were hidden somewhere in the residue. So I whipped up a computer program to output a ton of residues and search for patterns but I was of course wrong. However I did spot patterns.

I noticed that factorials "magically" revealed factors of numbers when they would pop up randomly in the residues they would factor the number.

If n! is between the factors of a number then it would factor the number with a gcd algorithm. The size of the numbers to factor would be about 300 digits long. Even more interesting, the gcd algorithm tells us if n! is larger or smaller than the factors if it doesn't find factors. So a logarithmic run time binary search can be used. This along with the fact that gcd () has a run time of log(x) means my algorithm has a log^2 (x) run time assuming we can find n! mod p efficiently. p is the number to be factored which is around 300 digits or more so it can compete with cuttent factoring algorithms. The n! Mod p is the first step in computing gcd (n !, p) using the extended Euclidian, and also the hardest step. Then all other steps will be trivial as n! mod p < p, and so the size of both inputs is no larger than p.

The best algorithms out there for finding n! Mod p do

... keep reading on reddit ➑

πŸ‘︎ 41
πŸ“°︎ r/math
πŸ’¬︎
πŸ‘€︎ u/wcb98
πŸ“…︎ Apr 21 2016
🚨︎ report
Looking for a quote on integer factorization

Apologies if this is the wrong place to post this. I'm running a workshop on public key cryptography soon and I'd like to be able to show a quote I saw a few months ago. It was a quote by someone in the 1800's (I think), basically saying:

> (some big number) is the product of (smaller number) and (smaller number), but I believe that only knowing the product no man would ever be able to know the two factors used in producing it

I haven't for the life of me been able to find this quote so I would appreciate any help. Thanks!

Edit - I found it! It's by William Stanley Jevons and the quote is as follows:

> Can the reader say what two numbers multiplied together will produce the number 8616460799? I think it unlikely that anyone but myself will ever know.

πŸ‘︎ 23
πŸ“°︎ r/math
πŸ’¬︎
πŸ‘€︎ u/jamesk727
πŸ“…︎ Oct 29 2016
🚨︎ report
Integers uniquely determined by their prime factorization...

Is there any way to make the primes a basis for a vector space (the integers)? I've been thinking about this all day, but no mater how I look at it, it falls apart somewhere. Addition would be defined as multiplication, and scalar multiplication would have to be exponentiation, but then it's no longer closed if the scalar is negative or non-integer. Is there anything I can do with this idea in some other section of math that doesn't care about it not being closed under scalar multiplication? I'm just really fond of the idea of for example expressing 54 as <1,3,0,0,....> or a vector one unit in the '2' direction and three units in the '3' direction... and maybe playing around with them from there...

Note: I'm in a linear algebra class at a community college, please try not to go too far over my head, thanks! Better yet, just tell me this is ridiculous so I can go back to actual assigned homework.

πŸ‘︎ 52
πŸ“°︎ r/math
πŸ’¬︎
πŸ‘€︎ u/cognificent
πŸ“…︎ Jun 14 2010
🚨︎ report
Is there a harder alternative to integer factorization for the purposes of cryptography?

I'm thinking of the (unlikely) case where P=NP is found. Since factorization is known to be in NP, this would likely lead to RSA being considered broken.

Is there a harder alternative that could be used in place of current systems for the purposes of public-key cryptography; or does the fact that if a problem can be verified in P then it is in NP break everything?

πŸ‘︎ 31
πŸ“°︎ r/compsci
πŸ’¬︎
πŸ‘€︎ u/FlightOfStairs
πŸ“…︎ Apr 26 2012
🚨︎ report
What would be the best thing to do if I, a college mathematician, solved large integer factorization problem in an efficient time.

I thought of several options:

  1. Publish
  2. Run to the Government
  3. Open a private firm offering decryption services with a stunning success. Are there other options?
πŸ‘︎ 4
πŸ“°︎ r/askmath
πŸ’¬︎
πŸ‘€︎ u/UltraB0b
πŸ“…︎ May 26 2017
🚨︎ report
Is integer factorization complexity really exponential?

I've been reading the Stanford Encyclopedia entry for Computational Complexity, and in paragraph 3.4.3 about parallel, probabilistic and quantum complexity, a statement is being made about Shor's algorithm that I don't really understand:

>... Shor’s algorithm (Shor 1999) for integer factorization (which runs in O(log2(n)^3 ), whereas the best known classical algorithm is O(2^log2(log2(n))^1/3 ))

Isn't 2^log2(y) by definition equal to y for any y? And doesn't this mean that O(2^log2(log2(n)) ) (which should be greater than O(2^log2(log2(n))^1/3 )) is actually equal to log2(n), making the traditional algorithm logarithmic rather than exponential?

edit: formatting

πŸ‘︎ 2
πŸ“°︎ r/compsci
πŸ’¬︎
πŸ‘€︎ u/zoeparman
πŸ“…︎ Jan 08 2016
🚨︎ report
Unique Factorization for Certain Subsets of the Integers

I've been working on a nifty program that takes subsets of the integers and determines whether there is unique factorization (by computing primes up to a number and factoring).

For example, take the integers greater than 3. 4 is prime because it can't factor. So are 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 (none factor). 16 is 4*4, so it's composite. Continuing this will eventually fail at unique factorization because 36 = 6*6 = 4*9, or 110 = 5*22 = 10*11, and many other examples.

Let's get weirder though. Take integer subsets of the form m*n+b, where n >= 0 and everything is an integer. For example, take 2, 5, 8, 11.... 2 is prime, 5 is prime, 8 is composite, 11 is prime, 14 is prime, and so on. This does not preserve unique factorization because 140 = 2*2*35 = 2*5*14 (and this is the first example!). Others, like n+2, 2n+3, 4n+2, 4n+6, 5x+7 (at least up to 160000*) (see here), all have unique factorization.

Is there a way to determine, given an m and b, whether or not the subset m*n+b preserves unique factorization? What are other subsets worth exploring?

πŸ‘︎ 8
πŸ“°︎ r/math
πŸ’¬︎
πŸ‘€︎ u/vlts
πŸ“…︎ May 10 2014
🚨︎ report
Is Number Field Sieve still the current state-of-the-art integer factorization method?
πŸ‘︎ 2
πŸ“°︎ r/askscience
πŸ’¬︎
πŸ‘€︎ u/sp31415926535
πŸ“…︎ Jun 07 2017
🚨︎ report
Show that for a positive integer n and a prime p, the largest power of p occurring in the prime factorization of n! is [n/p] + [n/(p^2)] + [n/(p^3)] + ...

x is a real number, where [x] is the largest integer m with m ≀ x.

We know n! = 1 * 2 * 3 .... n

and so,

(p, 2p, 3p, ...) => (n/p)

(p^2 , 2p^2 , ...) => (n/(p^2 ))

(p^3 , 2p^3 , ...) => (n/(p^3 ))

I don't know where to go from here.

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/Eksanol
πŸ“…︎ Sep 25 2017
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.