The Artima Developer Community
Sponsored Link

Java Answers Forum
Beginner, Can someone Please help with this Code ?

1 reply on 1 page. Most recent reply: May 30, 2004 7:37 AM by Philip Foulkes

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Tara

Posts: 3
Nickname: suzan
Registered: May, 2004

Beginner, Can someone Please help with this Code ? Posted: May 30, 2004 4:37 AM
Reply to this message Reply
Advertisement
hi guys im new to Java and i really need your help with this code, the program should encrypt and decrypt. For example encrypt a message of 10 charactors in length according to the rules below

The encryption is done by transposing characters using a given key stored as a string in the Encryptor class.Assume the key is "6230175498",then the character at index 0(the first character)is moved to position (index)6,the character at index 1 becomes the character at index 2, and so on ,for eg, "beam me up" will be "m ea ebmpu"
then have to write a class EncrypterTest to do 2 things


1- asks the user for 10 characters message ,encryps it and display the ecrypted message ,then decrypts it and display the decrypted message


2- asks the user for a message to decryp,then display the decrypted message .

this is my code so far its uncomplete and has errors, im kinda lost please help me to complete it or if u can or if u know simpler way to write it
1,000,000 thanks

public static void encrypt()
{
String input;
}

public static void decrypt()
{
}

public static void main(String[] args)
{
String key ;
String key2 ;

key = "6230175498";
Key2 = "0123456789";


String input = "Beam me up";

int x = 0;
int y = 0;



while (x < 10)
{

keyListing = key.charAt(x);

theKey = Character.getNumericValue(keyListing);

input2 = input.charAt(theKey);

System.out.print(input2);



x++;
}

While (y < 10)
{

keyListing = key.charAt(y);


theKey = Character.getNumericValue(keyListing);


input3 = input.charAt(theKey);

System.out.print(input3);



y++;

}


}




}


Philip Foulkes

Posts: 19
Nickname: frodo
Registered: May, 2004

Re: Beginner, Can someone Please help with this Code ? Posted: May 30, 2004 7:37 AM
Reply to this message Reply
/* Philip Foulkes
May 2004 */
public class Tara
{
	// Encrpy a String of length 10
	public static String encrypt (String input)
	{
		assert input.length() == 10;
		
		String key = "6230175498";
		char[] tmp = new char [10];
		
		for (int i = 0; i < 10; i++)
		{
			tmp[Character.getNumericValue(key.charAt(i))] = input.charAt(i);
		}
		
		return new String (tmp);
	}
 
	// Decrpy a String of length 10
	public static String decrypt (String input)
	{
		assert input.length() == 10;
		
		String key = /*INSERT YOUR CORRECT DECRPYT KEY HERE!*/;
		char[] tmp = new char [input.length()];
		
		for (int i = 0; i < input.length(); i++)
		{
			tmp[Character.getNumericValue(key.charAt(i))] = input.charAt(i);
		}
		
		return new String (tmp);
	}
 
	public static void main (String[] args) 
	{
		String input = "Beam me up";
		System.out.println (encrypt(input));
		System.out.println (decrypt(encrypt(input)));
	}
}

Flat View: This topic has 1 reply on 1 page
Topic: Date wanted. Previous Topic   Next Topic Topic: how to create fully working web browser using swings

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use