Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Implementing Sha256 and not getting the result I should get

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Implementing Sha256 and not getting the result I should get

    Hello there,
    The part in my program I'm stuck in gets a string, turns it to binary, pads the message and then divides it like Sha 256 does. Then, computes the hash with logical operations and bitwise operations.
    Everything goes smooth and the 256-bit digest is saved to a file called "hash", but it's not what I should get.
    For example: for string abc I should get:
    ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad
    But for some reason I don't.
    Last edited by ydan87; December 26th, 2011 at 03:31 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Implementing Sha256 and not getting the result I should get

    But for some reason I don't.
    What do you get?
    Have you worked through the math and the logic step by step to see where the program's computations and results differs from what you manually compute? When you find that point in the code, post what the manual results for the step is and show what the code does if you need help getting the code to do what your manual computations get.

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Implementing Sha256 and not getting the result I should get

    The result is
    f26cd891 87f5bf09 e14b7e36 2504dfec 307ed79c d1f3c788 e24793ec 00b1e84e

    I guess the mismatches begins in the extension from 16 to 64 part.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Implementing Sha256 and not getting the result I should get

    After you work through the equations manually and find where the code is not doing what you expect, post your questions about why the statement(s) is not working as you want.

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Implementing Sha256 and not getting the result I should get

    Man, I've been trying to do those things for days, I don't know what's wrong and where, If I would I would'nt post here. There's a certain peudo-code I've followed while writing the code, which is here:
    SHA-2 - Wikipedia, the free encyclopedia

    But again, I get a different result. maybe because all my variables are ints, I don't know! I need help to figure this out

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Implementing Sha256 and not getting the result I should get

    Add printlns to show the results after each step of the program. Compare what is printed out with your manual computations. When you find the statement where the output is not the same as your manual computations, post that statement and explain what values the statement had for input and what it computed and show your manual computations that shows what the value should be.

Similar Threads

  1. Result set is closed
    By keshav_agrawal89 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 11th, 2011, 08:35 AM
  2. The java-output doesn't give the right result?
    By pinotje in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 31st, 2011, 01:00 PM
  3. [NEED HELP] to clear result on my tic-tac-toe game
    By bontet in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 28th, 2010, 03:50 PM
  4. result set array button
    By dread_arisawa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 21st, 2010, 10:05 AM
  5. Problem of getting result than SQL to JTable
    By MS_Dark in forum Exceptions
    Replies: 1
    Last Post: March 10th, 2009, 06:26 AM