DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2008
    Posts
    1

    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

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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?

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    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

  1. soft drink Vending machine program
    By divagoddess in forum C++
    Replies: 5
    Last Post: 08-14-2009, 03:12 PM
  2. Pseudocode Problem
    By zobi316 in forum VB Classic
    Replies: 3
    Last Post: 03-10-2008, 07:05 AM
  3. Help with Server program
    By sedricbenson@ho in forum C++
    Replies: 2
    Last Post: 11-07-2006, 08:18 AM
  4. Connecting to a Server Program HELP
    By sedricbenson@ho in forum C++
    Replies: 2
    Last Post: 11-07-2006, 07:58 AM
  5. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 10:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links