-
Please help with enscryption program
The idea of this program is to read input from the keyboard and convert it into ciphertext using P^3 mod 33. First though CAP letters only must correspond to their numeric value (A=1, B = 2, C = 3...). For example if I input ANNE
output 1 5 5 26
Is the try catch in the right place or do I even need it?
import java.util.Scanner.*;
import java.io.*;
public class RSA {
public static void main (String[] args)
{
InputStreamReader istream = new InputStreamReader(System.in) ;
BufferedReader bufRead = new BufferedReader(istream);
String message = bufRead.readLine();
String encryptedString = "";
// convert str to a char array so I can access
// digit by digit
char[] digit = message.toCharArray();
// loop through the digit and print the position of each letter
for(int i = 0; i < digit.length; i++)
{
// init rank to 0
int rank = 0;
// test if letter from a to z
if(digit[i] >= 'a' && digit[i] <= 'z')
{
rank = digit[i] - 'a' + 1;
}
// test if letter from A to Z
if(digit[i] >= 'A' && digit[i] <= 'Z')
{
rank = digit[i] - 'A' + 1;
}
if(rank != 0) {
// raise to power of 3
int power = rank * rank * rank;
// modulo 33
power %= 33;
encryptedString = encryptedString + " " + power;
}
System.out.println("Please enter the message you wish to send: ");
System.out.println();
System.out.println ("You entered: " + message + "");
System.out.println ();
System.out.println ("Therefore plaintext is: " + message + "");
System.out.println ("Encrypted string : " + encryptedString + "");
}
{
System.out.println("Error reading line");
}
}
}
Thanks in advance
-
I don't see a try ... catch in the code you've posted.
You need some organization to your code. Are you going to define methods in your class [stuff like a constructor, getUserInput, encrypt, decrypt], have some data fields, provide some structure other than trying to put all your code in a method main?
-
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
Similar Threads
-
By divagoddess in forum C++
Replies: 5
Last Post: 08-14-2009, 03:12 PM
-
By zobi316 in forum VB Classic
Replies: 3
Last Post: 03-10-2008, 07:05 AM
-
By sedricbenson@ho in forum C++
Replies: 2
Last Post: 11-07-2006, 08:18 AM
-
By sedricbenson@ho in forum C++
Replies: 2
Last Post: 11-07-2006, 07:58 AM
-
By Gordon Reichhardt in forum VB Classic
Replies: 2
Last Post: 01-08-2002, 10:06 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks