is this code correct?
Code:
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Scanner;
public class Encrypter {
public static void main(String[] args)
{
int groupSize = 100;
Scanner input = new Scanner(System.in);
BigInteger prime = new BigInteger("58021664585639791181184025950440248398226136069516938232493687505822471836536824298822733710342250697739996825938232641940670857624514103125986134050997697160127301547995788468137887651823707102007839");
BigInteger exponent = new BigInteger("499490918065850301921197603564081112780623690273420984342968690594064612108591217229304461006005170865294466527166368851");
System.out.printf("The prime we are using is %S\n", prime);
System.out.printf("The exponent we will use is %S\n", exponent);
System.out.printf("(prime-1,exponent) = %d\n", exponent.gcd(prime.subtract(BigInteger.ONE)));
System.out.printf("Using groups of %d numbers at a time because \n", groupSize);
for(int i = 0; i < groupSize; i++)
{
System.out.printf("25");
}
System.out.printf("\n < \n%S\n < \n", prime);
for(int i = 0; i < groupSize+1; i++)
{
System.out.printf("25");
}
System.out.printf("\n");
System.out.printf("Enter the text to be encrypted: ");
String plaintext = input.nextLine();
LinkedList<BigInteger> groups = convertToNumbers(plaintext, groupSize);
System.out.printf("The string converted to numbers is: ");
for(int i = 0; i < groups.size(); i++)
{
System.out.printf("%S\n", groups.get(i));
}
System.out.printf("The ciphertext is: ");
for(int i = 0; i < groups.size(); i++)
{
String s = groups.get(i).modPow(exponent, prime).toString();
for(int j = 0; j < 4-s.length(); j++)
{
System.out.printf("0");
}
System.out.printf("%S", s);
}
}
private static LinkedList<BigInteger> convertToNumbers(String value, int groupSize)
{
StringBuilder i = new StringBuilder();
LinkedList<BigInteger> group = new LinkedList<BigInteger>();
value = value.toLowerCase();
for(int j = 0, k = 0; j < value.length(); j++,k++)
{
if(k == groupSize)
{
k = 0;
group.add(new BigInteger(i.toString()));
i = new StringBuilder();
}
if(value.charAt(j) == 32)
{
k--;
continue;
}
if(value.charAt(j)-97 < 10)
i.append(0);
i.append(value.charAt(j)-97);
}
if(i.length() != 0)
{
group.add(new BigInteger(i.toString()));
}
return group;
}
}
I would also know if anyone knows of a program that would be good for a demonstation of cracking a cipher of this type?
__________________