Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 3 Weeks Ago   #1 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Nov 2007
Location: Surrey, BC, Canada
Posts: 272

Rep: 14 serge2k Unknown
Unique Rep: 14
Trader Rating: 1
Default Exponentiation cipher

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?
__________________
System: The Black Box
CPU
E6750
Motherboard
Asus P5N-E SLI
Memory
2GB DDR-2 800 MHz
Graphics Card
EVGA 8800 GTS 640
Hard Drive
2x250GB Seagate in Raid 0, 2x1TB WD Caviar Blacks
Sound Card
integrated
Power Supply
Antec Earthwatts 500W
Case
Antec Sonata 3
CPU cooling
Xigmatek HDT S1283
GPU cooling
stock
OS
Windows 7 Ultimate x64
Monitor
22" LG
serge2k is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 11:06 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.08072 seconds with 8 queries