Please help with enscryption program


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Please help with enscryption program

  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,666
    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, 04:12 PM
  2. Pseudocode Problem
    By zobi316 in forum VB Classic
    Replies: 3
    Last Post: 03-10-2008, 08:05 AM
  3. Help with Server program
    By sedricbenson@ho in forum C++
    Replies: 2
    Last Post: 11-07-2006, 09:18 AM
  4. Connecting to a Server Program HELP
    By sedricbenson@ho in forum C++
    Replies: 2
    Last Post: 11-07-2006, 08:58 AM
  5. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 11: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center