PDA

View Full Version : JAVA HELP



Angrafan
11-03-2004, 13:31
An kserei kaneis java, PARAKALW na apanthsei oso pio grigora ginete, efxaristw

IrDA
11-03-2004, 13:38
Den mas les kai to problhma outws wste opoios 3erei th lush sto problhma na apanthsei ?

Angrafan
11-03-2004, 13:40
Write a class called Encryption which allows you to encrypt a message using a secret code word and to decrypt an encrypted message. You will need to provide the following methods: A constructor which takes a String parameter and saves it as the encryption key (referred to as k in the description below). This will be a 26-character value consisting of a shuffled version of the alphabet.
A method called encrypt which encrypts a message, taking a String parameter and returning a String result. The result is produced by converting the parameter to upper-case, and replacing each letter by the corresponding letter from k. Other characters (punctuation, spaces etc.) should be left unchanged.
A method called decrypt which decrypts a message, taking a String parameter and returning a String result. The result is produced by converting the parameter to upper-case, and replacing each letter by the letter corresponding to its position in k. Other characters (punctuation, spaces etc.) should be left unchanged.

For example, if k = "THEQUICKBROWNADFGJLMPSVXYZ", the letters in any message are replaced as follows: From: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
To: T H E Q U I C K B R O W N A D F G J L M P S V X Y Z


This means that encrypt("Hello world") should return "KUWWD VDJWQ". Decryption reverses the process, so decrypt("kuwwd vdjwq") should return "HELLO WORLD".
Some hints to help you along: You can convert a string s to upper-case using the toUpperCase method from class String:

s = s.toUpperCase(); // convert s to upper-case


You can select the n-th character of a string using the charAt method from class String, where the characters are numbered starting from zero:

char c = s.charAt(n); // get the n-th character of s (n = 0 gets the first character)


You can convert a letter A to Z into a number 0 to 25 by subtracting 'A':

int n = c - 'A'; // convert character c into a number n (0 to 25)


You can convert a number between 0 to 25 to a letter by adding 'A':

char c = (char)(n + 'A'); // convert number n (0 to 25) to a character c


You can find the first position of a character in a string using the indexOf method from class String, where the characters are numbered starting from zero:

String s = "ABCDE";
int n = s.indexOf('D'); // get the position of the first 'D' in s (n = 3 in this case)

cloud
12-03-2004, 13:23
Ayto to hello world exw varethei na to vlepw se askhseis programmatismou.