/**
 * An application for encrypting with RSA
 *
 * usage: java RSAEncrypt n key
 *  - read a message from the standard input
 *  - write to the standard output the corresponding encrypted message,
 *    as a list of big integers, one per line;
 *    some comments are included in lines starting with '#'
 *
 * @version	$Id: RSAEncrypt.java,v 1.1.2.1 2003/11/26 10:53:19 nthiery Exp $
 * @author	Nicolas M. Thiéry <nthiery@users.sourceforge.net>
**/

import java.math.BigInteger;
import java.util.List;
import java.util.Iterator;
import java.util.Date;
import java.text.DateFormat;
import java.io.*;

public class RSAEncrypt {
    public static void main(String[] args) throws java.io.IOException {
	BigInteger n = new BigInteger(args[0]);
	BigInteger key = new BigInteger(args[1]);

	System.out.println("# Message encrypted by " +
			   System.getProperty("user.name") +
			   " on " +
			   DateFormat.getDateInstance().format(new Date()));
	System.out.println("# n = " + n);

	String message = "";
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	String line;
	while( (line=in.readLine())!=null ) {
	    message+=line;
	}
	List messageEncrypted=RSA.rsa(RSA.encode(message,n), n, key);
	for(Iterator it=messageEncrypted.iterator(); it.hasNext();) {
	    System.out.println(it.next());
	}
    }
}
