/*
    Tom Long
    RSA buster - once you have already factored 'n'

    compilation: javac RSA.java
    execuction : java RSA
    recommended excecution java RSA > output.txt
        redirect the output so you can play with it
    NOTE--This is set to break 2001 RSA "easy", JUST SUBSTITUTE the 
    CORRECT VALUES n, p, q, e AS NEEDED

    NOTE: The file named "in.txt" contains the cipher-text and should be 
          located
          in the same directory as RSA.class, otherwise "in.txt" should be the
          absolute path to the cipher-text file.
*/

import java.math.BigInteger;
import java.io.*;

public class RSA{
    public static void main(String args[]) throws IOException{

        DataInput  in_file = new DataInputStream(new FileInputStream("in.txt"));
        String     next_line;
        BigInteger n = new BigInteger("1523853391612839972163159");
        BigInteger p = new BigInteger("            ");/* enter p-1 */
        BigInteger q = new BigInteger("            ");/* enter q-1 */
        BigInteger e = new BigInteger("742119557");
        BigInteger phi_of_n, d, plain_text;
                   
        phi_of_n  = p.multiply(q);
        d         = e.modInverse(phi_of_n);

        while ((next_line = in_file.readLine()) != null){
            if (next_line.length() > 0){
                plain_text = new BigInteger(next_line);
                plain_text = plain_text.modPow(d, n);
                System.out.println(plain_text.toString());
            }
        }
    }
}

