Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28
  1. #21
    mzjazzygirl is offline Member
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default

    Norm,

    I think I fixed the incompatability issue...

    Now I am having trouble w/doing a constant divide. I am trying to use the divideAndRemainder() function, save the remainder, and display it as a character. I have attached the code, and output of where I am stuck.

    import java.io.*;
    import java.math.*;
    import java.util.*;

    public class Homework1 {
    static BigInteger[] great;
    static BigInteger[] key;
    static char[] plaintext = new char[1000];
    static int count;
    static int count1;
    static int count2;
    static long base = 128;
    static BigInteger base2 = BigInteger.valueOf(base);

    public static BigInteger readKey() throws IOException
    {
    FileReader fr1 = new FileReader("key.txt");
    BufferedReader br1 = new BufferedReader(fr1);
    String line;
    count1 = 0;
    while((line = br1.readLine()) != null)
    {
    key[count1] = new BigInteger(line);
    //System.out.println("Line... " +line);
    count1++;
    }
    //System.out.println("Let's see... "+ key[0]);
    fr1.close();
    return key[0];
    }

    public static void readPlainText() throws IOException
    {
    FileReader fr2 = new FileReader("plaintext.txt");
    BufferedReader br2= new BufferedReader(fr2);
    String line1;
    String temp;
    int temp2[] = new int[10000];
    StringBuilder sb = new StringBuilder();
    BigInteger code;

    count2 = 0;
    while((line1 = br2.readLine()) != null)
    {
    line1.getChars(0, line1.length(), plaintext, 0);
    for(int k = 0; k < line1.length(); k++)
    {
    temp2[count2] = (int)plaintext[k] * 128;
    sb.append(temp2[count2]);
    count++;
    }
    }
    fr2.close();

    BigInteger temp3 = new BigInteger(sb.toString());
    code = temp3.multiply(key[0]);

    try{
    PrintStream out = new PrintStream(new FileOutputStream("encryption.txt"));
    out.println(code);
    out.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
    }

    public static void readBigNumbers(BigInteger temp3) throws IOException
    { FileReader fr = new FileReader("encryption.txt");
    BufferedReader br = new BufferedReader(fr);


    String line;
    //System.out.println("New base from 128, to big integer... "+ base2);
    count = 0;
    while ((line = br.readLine()) != null)
    { great[count] = new BigInteger(line);
    //System.out.println(great[count]);
    count++;
    }
    fr.close();

    System.out.println("Test 1... "+great[0]); //Encryption file
    System.out.println("Test 2... "+temp3); //Key

    BigInteger storage = new BigInteger(great[0].toString());
    BigInteger k_temp = new BigInteger(temp3.toString());
    //System.out.println("Prelim test..." +storage);
    //System.out.println("New prelim test..." +k_temp);

    BigInteger storage1[] = storage.divideAndRemainder(k_temp);
    BigInteger storage2[] = storage1[0].divideAndRemainder(base2);

    System.out.println("This is being shown...");
    System.out.println("What is this? "+storage2[1].toString());

    *while(storage2[1] != BigInteger.valueOf(0))*
    *{*
    *System.out.println(storage2[1]);*
    *System.out.println("Is this going to show?");*
    *storage1[0].divideAndRemainder(base2);*
    *}*

    System.out.println("Or what about this?");
    System.out.println("Quotient... "+storage.divide(k_temp));
    /*System.out.println("Integral part... "+storage[1]);
    System.out.println("Remainder... "+storage[1]);*/



    }

    public static void main(String argv[])throws IOException
    { great = new BigInteger[100];
    key = new BigInteger[5];
    String line;
    int selection = 0;
    BigInteger temp2;

    System.out.println("Please make your selection.\n 1. Encryption \n 2. Decryption\n");
    try{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    line = in.readLine();
    selection = Integer.parseInt(line);
    }
    catch (IOException e) {
    System.out.println("Unexpected IO Error: " + e);
    }
    switch(selection) {

    case 1:
    System.out.println("You have selected Encryption.");
    temp2 = readKey();
    readPlainText();
    System.out.println("The encryption.txt file has been created.");
    break;

    case 2:
    System.out.println("You have selected Decryption.");
    temp2 = readKey();
    readBigNumbers(temp2);
    /* System.out.println("\n Printing from great[] \n");
    for (int i = 0; i < count; i++)
    System.out.println(great[i].toString());*/
    break;
    }


    System.out.println("\n *** Program Finished *** ");
    }

    }


    Output that I am getting:
    Please make your selection.
    1. Encryption
    2. Decryption

    2
    You have selected Decryption.
    Encryption... 20436095433186426617233657404817259315569049355510 36645458759259730927
    3543083039960605160641280
    Key... 21574986861247560388341
    This is being shown...
    What is this? 0 <== This is SUPPOSED to be the division, showing zero
    Or what about this?
    Quotient... 94721241614720139521344014080129284096947212416126 721369614720142081
    4080

    *** Program Finished ***

    Any assistance would be great.

    Thanks!

  2. #22
    mzjazzygirl is offline Member
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default

    Java Code:
    import java.io.*;
    import java.math.*;
    import java.util.*;
    
    public class Homework1 {
    static BigInteger[] great; 
    static BigInteger[] key;
    static char[] plaintext = new char[1000];
    static int count;
    static int count1;
    static int count2;
    static long base = 128;
    static BigInteger base2 = BigInteger.valueOf(base);
    
    public static BigInteger readKey() throws IOException
    {
    FileReader fr1 = new FileReader("key.txt");
    BufferedReader br1 = new BufferedReader(fr1);
    String line;
    count1 = 0;
    while((line = br1.readLine()) != null)
    {
    key[count1] = new BigInteger(line);
    //System.out.println("Line... " +line);
    count1++;
    }
    //System.out.println("Let's see... "+ key[0]);
    fr1.close();
    return key[0];
    }
    
    public static void readPlainText() throws IOException
    {
    FileReader fr2 = new FileReader("plaintext.txt");
    BufferedReader br2= new BufferedReader(fr2);
    String line1;
    String temp;
    int temp2[] = new int[10000];
    StringBuilder sb = new StringBuilder();
    BigInteger code;
    
    count2 = 0;
    while((line1 = br2.readLine()) != null)
    {
    line1.getChars(0, line1.length(), plaintext, 0);
    for(int k = 0; k < line1.length(); k++)
    {
    temp2[count2] = (int)plaintext[k] * 128; 
    sb.append(temp2[count2]);
    count++;
    }
    }
    fr2.close();
    
    BigInteger temp3 = new BigInteger(sb.toString());
    code = temp3.multiply(key[0]);
    
    try{
    PrintStream out = new PrintStream(new FileOutputStream("encryption.txt"));
    out.println(code);
    out.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
    }
    
    public static void readBigNumbers(BigInteger temp3) throws IOException
    { FileReader fr = new FileReader("encryption.txt");
    BufferedReader br = new BufferedReader(fr);
    
    
    String line;
    //System.out.println("New base from 128, to big integer... "+ base2);
    count = 0;
    while ((line = br.readLine()) != null)
    { great[count] = new BigInteger(line);
    //System.out.println(great[count]);
    count++;
    }
    fr.close();
    
    System.out.println("Test 1... "+great[0]); //Encryption file
    System.out.println("Test 2... "+temp3); //Key
    
    BigInteger storage = new BigInteger(great[0].toString());
    BigInteger k_temp = new BigInteger(temp3.toString());
    //System.out.println("Prelim test..." +storage);
    //System.out.println("New prelim test..." +k_temp);
    
    BigInteger storage1[] = storage.divideAndRemainder(k_temp);
    BigInteger storage2[] = storage1[0].divideAndRemainder(base2);
    
    System.out.println("This is being shown...");
    System.out.println("What is this? "+storage2[1].toString());
    
    *while(storage2[1] != BigInteger.valueOf(0))*
    *{*
    *System.out.println(storage2[1]);*
    *System.out.println("Is this going to show?");*
    *storage1[0].divideAndRemainder(base2);*
    *}*
    
    System.out.println("Or what about this?");
    System.out.println("Quotient... "+storage.divide(k_temp));
    /*System.out.println("Integral part... "+storage[1]);
    System.out.println("Remainder... "+storage[1]);*/
    
    
    
    }
    
    public static void main(String argv[])throws IOException
    { great = new BigInteger[100];
    key = new BigInteger[5];
    String line;
    int selection = 0;
    BigInteger temp2;
    
    System.out.println("Please make your selection.\n 1. Encryption \n 2. Decryption\n");
    try{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    line = in.readLine();
    selection = Integer.parseInt(line);
    }
    catch (IOException e) {
    System.out.println("Unexpected IO Error: " + e);
    }
    switch(selection) {
    
    case 1: 
    System.out.println("You have selected Encryption.");
    temp2 = readKey();
    readPlainText();
    System.out.println("The encryption.txt file has been created.");
    break;
    
    case 2:
    System.out.println("You have selected Decryption.");
    temp2 = readKey();
    readBigNumbers(temp2);
    /* System.out.println("\n Printing from great[] \n");
    for (int i = 0; i < count; i++)
    System.out.println(great[i].toString());*/
    break;
    }
    
    
    System.out.println("\n *** Program Finished *** ");
    }
    
    }
    Java Code:
    Output that I am getting:
    Please make your selection.
    1. Encryption
    2. Decryption
    
    2
    You have selected Decryption.
    Encryption... 20436095433186426617233657404817259315569049355510 36645458759259730927
    3543083039960605160641280
    Key... 21574986861247560388341
    This is being shown...
    What is this? 0 <== This is SUPPOSED to be the division, showing zero
    Or what about this?
    Quotient... 94721241614720139521344014080129284096947212416126 721369614720142081
    4080
    
    *** Program Finished ***

  3. #23
    mzjazzygirl is offline Member
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default

    Java Code:
    Output that I am getting:
    Please make your selection.
    1. Encryption
    2. Decryption
    
    2
    You have selected Decryption.
    Encryption... 20436095433186426617233657404817259315569049355510 36645458759259730927
    3543083039960605160641280
    Key... 21574986861247560388341
    This is being shown...
    What is this? 0 <== This is SUPPOSED to be the remainder, showing zero
    Or what about this?
    Quotient... 94721241614720139521344014080129284096947212416126 721369614720142081
    4080
    
    *** Program Finished ***

  4. #24
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Now also on another forum
    Java Programming - Problems w/BigIntegers

    db

  5. #25
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please do not cross-post without informing us. Keep doing this and folks might decide not to help you in the future (here or in other forums). Best of luck.

  6. #26
    mzjazzygirl is offline Member
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default

    Darrl.Burke and Fubarable,

    I am very sorry about the cross-post. I didn't know these two sites were related, or the same.

    It will not happen again.

    Thank you for your help.

    -mzjazzygirl

  7. #27
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    They're not related, but it is annoying to answer a question in a forum only to discover that it has already been answered on another forum. Never mind being something of a waste of time.

    By the way, is your code normally unformatted like that?

  8. #28
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

Page 2 of 2 FirstFirst 12

Similar Threads

  1. BigInteger
    By windows.login in forum New To Java
    Replies: 8
    Last Post: 07-13-2010, 01:10 PM
  2. convert unsigned integer to signed integer in java?
    By diskhub in forum New To Java
    Replies: 6
    Last Post: 05-17-2010, 12:50 AM
  3. My own BigInteger class. Need help.
    By Dinde in forum New To Java
    Replies: 2
    Last Post: 01-27-2010, 08:49 PM
  4. Replies: 24
    Last Post: 05-18-2009, 10:23 AM
  5. how to convert from BigInteger to Hex
    By nanaji in forum Advanced Java
    Replies: 10
    Last Post: 05-22-2008, 12:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •