Results 1 to 6 of 6
  1. #1
    java_idiot is offline Member
    Join Date
    Mar 2010
    Posts
    7
    Rep Power
    0

    Default y the results in GUI are not the same with the result in command prompt?

    Can someone tell me why the result i get in GUI is not the same with the result in command prompt??:(

    the result in cmd is correct but the result in GUI is wrong...

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Something is wrong with your code.

    We don't have your code so we can't say exactly what is wrong with it.

  3. #3
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    something "very" critical is missing from your question.

    try psting the code

  4. #4
    java_idiot is offline Member
    Join Date
    Mar 2010
    Posts
    7
    Rep Power
    0

    Default

    here's are part of the coding...

    >>main.java
    else if (cbSelection.getSelectedIndex() == 2)
    {
    sha256Words s256w = new sha256Words();
    shaOutput.txtResults.append("<<< Initialize variables >>>\n");
    shaOutput.txtResults.append("H0: "+Integer.toHexString(sha256InitialHash.h0).toUppe rCase());
    shaOutput.txtResults.append("\nH1: "+Integer.toHexString(sha256InitialHash.h1).toUppe rCase());
    shaOutput.txtResults.append("\nH2: "+Integer.toHexString(sha256InitialHash.h2).toUppe rCase());
    shaOutput.txtResults.append("\nH3: "+Integer.toHexString(sha256InitialHash.h3).toUppe rCase());
    shaOutput.txtResults.append("\nH4: "+Integer.toHexString(sha256InitialHash.h4).toUppe rCase());
    shaOutput.txtResults.append("\nH5: "+Integer.toHexString(sha256InitialHash.h5).toUppe rCase());
    shaOutput.txtResults.append("\nH6: "+Integer.toHexString(sha256InitialHash.h6).toUppe rCase());
    shaOutput.txtResults.append("\nH7: "+Integer.toHexString(sha256InitialHash.h7).toUppe rCase()+ "\n\n");
    shaOutput.txtResults.append("<<< Message Padding >>>\n");
    shaOutput.txtResults.append("-->Append '1' to message\n");
    shaOutput.txtResults.append("-->Append 0<=k<=512 '0's to message\n");
    shaOutput.txtResults.append("-->Append length of message in bits\n");


    if(message.length()== 0)
    {
    int reply = JOptionPane.showConfirmDialog(null, "The message field is left blank.\nThe system will continue with Message Padding process ! ! !\nClick Yes if you wish to continue, No to stay remain on this page...", "Message Field Left Blank", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

    if(reply == JOptionPane.YES_OPTION){
    shaOutput.txtM_Hex.setText("No message to be encrypted...");
    shaOutput.txtM_Bin.setText("No message to be encrypted...");
    padBin = "1";
    bin = padBin;
    while (bin.length()!=512)
    {
    padBin = "0";
    bin = bin+padBin;
    count0 += padBin.replaceAll("[^0]","").length();
    }
    shaOutput.txtResults.append("No of '0's padded: "+Integer.toString(count0));

    shaOutput.txtResults.append("\nPadded Message (in Binary): \n");

    char afterPaddingBin [] = new char[bin.length()];

    afterPaddingBin = bin.toCharArray();
    int count = 1;
    for(int i=0; i<bin.length(); i++){
    shaOutput.txtResults.append(""+afterPaddingBin[i]);
    if(count%8==0){
    shaOutput.txtResults.append(" ");
    }
    count++;
    }
    String sub;
    String isub;
    int sub2;
    shaOutput.txtResults.append("\n\nPadded Message (in Hexadecimal): \n");

    for (int i=0; i<bin.length(); i+=8)
    {
    sub = bin.substring(i,i+8);
    sub2 = Integer.parseInt(sub,2);
    isub = Integer.toHexString(sub2);
    if (isub.length() == 1)
    {
    isub = "0"+isub;
    }
    padHex += isub;
    padHex = padHex.replaceAll("null", "");
    }

    char afterPaddingHex [] = new char[padHex.length()];
    afterPaddingHex = padHex.toCharArray();
    for(int i=0; i<padHex.length(); i++)
    {
    padHex2 += afterPaddingHex[i];
    if(count%8==0)
    {
    padHex2 = padHex2+" ";
    }
    count++;
    padHex2 = padHex2.replaceAll("null", "");
    }
    shaOutput.txtResults.append(padHex2);

    s2Words = s256w.calc256Words(padHex2);
    for (int i=0; i<64; i++)
    {
    s2w[i] = Long.toHexString(s2Words[i]).toUpperCase();
    while (s2w[i].length()<8)
    {
    s2w[i]="0"+s2w[i];
    }
    if(s2w[i].length()>8)
    {
    int xtra = s2w[i].length() - 8;
    s2w[i]=s2w[i].substring(xtra, s2w[i].length());
    }
    shaOutput.txtResults.append("\nWord["+i+"]:"+s2w[i]);
    shaOutput.setVisible(true);
    setVisible(false);
    }


    >>sha256Words.java
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package SHA256;

    /**
    *
    * @author s.n.tan
    */
    import Main.shaEncrypt;
    public class sha256Words {

    private int i;
    shaEncrypt sha256Encrypt = new shaEncrypt();
    long words[] = new long[64];
    String[] msg;
    long msg1[] = new long[16];
    String sha256Words[] = new String[64];
    long sig0[] = new long[48];
    long sig1[] = new long[48];

    public long[] calc256Words(String padHex2)
    {
    msg = padHex2.split(" ");
    for (String a: msg)
    {
    System.out.println(a);
    }

    for (i=0; i<16; i++)
    {
    msg1[i] = Long.parseLong(msg[i],16);
    words[i] = msg1[i];
    sha256Words[i] = Long.toHexString(words[i]);
    while (sha256Words[i].length()<8)
    {
    sha256Words[i]="0"+sha256Words[i];
    }
    System.out.println("w["+i+"]: " +sha256Words[i]);
    }
    int count = 0;
    for (i=16; i<64; i++)
    {
    sig0[count]= (words[i-15]<<25|words[i-15]>>7)^(words[i-15]<<14|words[i-15]>>18)^(words[i-15]>>3);
    sig1[count]= (words[i-2]<<15|words[i-2]>>17)^(words[i-2]<<13|words[i-2]>>19)^(words[i-2]>>10);
    words[count]=sig1[count]+words[i-7]+sig0[count]+words[i-16];

    String binWords = Long.toBinaryString(words[count]);

    while (binWords.length()< 32)
    {
    binWords = "0" + binWords;
    }
    if (binWords.length()>32)
    {
    int xtra = binWords.length()-32;
    binWords = binWords.substring(xtra, binWords.length());
    }
    words[count] = Long.parseLong(binWords, 2);
    words[i] = words[count];
    sha256Words[i] = Long.toHexString(words[i]);
    while (sha256Words[i].length()<8)
    {
    sha256Words[i]="0"+sha256Words[i];
    }
    if(sha256Words[i].length()>8){
    int xtra = sha256Words[i].length() - 8;
    sha256Words[i]=sha256Words[i].substring(xtra, sha256Words[i].length());
    }
    System.out.println("Word["+i+"]: "+sha256Words[i]);
    count++;
    }
    sha256Encrypt.setS2Words(words);
    return words;
    }
    }

  5. #5
    java_idiot is offline Member
    Join Date
    Mar 2010
    Posts
    7
    Rep Power
    0

    Default

    actually, i use the same method for the other option. It works...but i don't know why the output in cmd n output in GUI are different in this option

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You should have formatted the code and posted it wrapped with code tags to make it more redable.
    What exact difference are you getting? You are obviously not sending the same string to your GUI that you are sending to your console somewhere. You have lots of sysouts in your code so you need to say which one you are not getting to your GUI.
    Last edited by r035198x; 05-10-2010 at 08:45 AM.

Similar Threads

  1. CORBA command prompt
    By ntagrafix in forum Advanced Java
    Replies: 2
    Last Post: 04-06-2010, 12:35 PM
  2. Command Prompt Java
    By kelvinsmj in forum New To Java
    Replies: 8
    Last Post: 11-27-2009, 11:30 AM
  3. How to run a project with the command prompt?
    By TexanProgrammer in forum NetBeans
    Replies: 4
    Last Post: 08-05-2009, 11:19 PM
  4. how to get the values from command prompt
    By tej in forum New To Java
    Replies: 3
    Last Post: 05-02-2009, 09:32 AM
  5. help me!!!! about command prompt..
    By kureikougaiji in forum New To Java
    Replies: 2
    Last Post: 11-13-2008, 07:15 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
  •