Need some help confirming transactions using sha256

Discussion in 'Python' started by kryptox.exchange@gmail.com, Jan 31, 2013.

  1. Guest

    I'm wondering if anyone can help me as I can't seem to get this to work. There is an online dice game that is provably fair by calculating the 'dice roll' using using a sha256 hash calculated against my transaction ID generated by me. The secret used to make the calculation is revealed at the end ofeach day thus allowing you to prove they didn't cheat. So they provide thefollowing to allow you to verify the calculation of the dice roll:

    Secret used = r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA
    Secret hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA) = 48d78d573b9b8e11a13a72d9a78011f2e5d9754d89de47b209f32c51777f535d
    Lucky hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA:108128 06653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1) = dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4

    Lucky Number 0x48e4 = 18660


    So, I'm doing the following:

    C:\Python27>python
    Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import hashlib, hmac
    >>> txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA'
    >>> secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1'
    >>> for nout in range(10): print nout, int(hmac.new(secret, "%s:%d" % (txid, nout), hashlib.sha256).hexdigest()[:4], 16)

    ....
    0 39800
    1 4705
    2 24058
    3 11188
    4 36307
    5 781
    6 62165
    7 44612
    8 17042
    9 46099
    >>>


    idx 1 should equal 18660 but it doesn't. What am I doing wrong?


    Secondly, I'm wondering if someone could help take it one step further. I would like to import a .txt file with a unique transaction ID on each line. So txid = transactions.txt or something like this. I would like it to getthe "lucky number" based on a static sha256 which I would supply and the script would output the result to a text file. I'd like the output to be foridx 1 only.

    ie.
    "txid here", "lucky number for idx 1"

    Thanks for any help in advance!

    Edit/Delete Message
    , Jan 31, 2013
    #1
    1. Advertising

  2. Guest

    Ok, I'm still stuck! :(

    I do however now think that I'm not supposed to use hmac here.
    , Jan 31, 2013
    #2
    1. Advertising

  3. On Thu, 31 Jan 2013 08:43:03 -0800 (PST), wrote:

    > I'm wondering if anyone can help me as I can't seem to get
    > this to work. There is an online dice game that is
    > provably fair by calculating the 'dice roll' using using a
    > sha256 hash calculated against my transaction ID generated
    > by me. The secret used to make the calculation is revealed
    > at the end of each day thus allowing you to prove they
    > didn't cheat. So they provide the following to allow you
    > to verify the calculation of the dice roll:
    >
    > Secret used = r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA
    > Secret hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA) = 48d78d573b9b8e11a13a72d9a78011f2e5d9754d89de47b209f32c51777f535d
    > Lucky hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA:108128 06653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1) = dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4
    >
    > Lucky Number 0x48e4 = 18660
    >
    > So, I'm doing the following:
    >
    > C:\Python27>python
    > Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
    > Type "help", "copyright", "credits" or "license" for more information.
    >>>> import hashlib, hmac
    >>>> txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA'
    >>>> secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1'

    [snip]

    >>> txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA'
    >>> secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1'
    >>> hashlib.sha256(txid+":"+secret).hexdigest()

    'dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4'
    >>> 0x48e4

    18660
    >>>


    .. . . which is the number you wanted, right?


    --
    To email me, substitute nowhere->spamcop, invalid->net.
    Peter Pearson, Jan 31, 2013
    #3
  4. Guest

    On Thursday, January 31, 2013 6:55:05 PM UTC+1, Peter Pearson wrote:
    > On Thu, 31 Jan 2013 08:43:03 -0800 (PST), wrote:
    >
    >
    >
    > > I'm wondering if anyone can help me as I can't seem to get

    >
    > > this to work. There is an online dice game that is

    >
    > > provably fair by calculating the 'dice roll' using using a

    >
    > > sha256 hash calculated against my transaction ID generated

    >
    > > by me. The secret used to make the calculation is revealed

    >
    > > at the end of each day thus allowing you to prove they

    >
    > > didn't cheat. So they provide the following to allow you

    >
    > > to verify the calculation of the dice roll:

    >
    > >

    >
    > > Secret used = r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA

    >
    > > Secret hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA) = 48d78d573b9b8e11a13a72d9a78011f2e5d9754d89de47b209f32c51777f535d

    >
    > > Lucky hash sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA:108128 06653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1) = dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4

    >
    > >

    >
    > > Lucky Number 0x48e4 = 18660

    >
    > >

    >
    > > So, I'm doing the following:

    >
    > >

    >
    > > C:\Python27>python

    >
    > > Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32

    >
    > > Type "help", "copyright", "credits" or "license" for more information.

    >
    > >>>> import hashlib, hmac

    >
    > >>>> txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA'

    >
    > >>>> secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1'

    >
    > [snip]
    >
    >
    >
    > >>> txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA'

    >
    > >>> secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1'

    >
    > >>> hashlib.sha256(txid+":"+secret).hexdigest()

    >
    > 'dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4'
    >
    > >>> 0x48e4

    >
    > 18660
    >
    > >>>

    >
    >
    >
    > . . . which is the number you wanted, right?
    >
    >
    >
    >
    >
    > --
    >
    > To email me, substitute nowhere->spamcop, invalid->net.



    Yes, thank you Peter!
    , Jan 31, 2013
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    409
    Klaas
    Dec 20, 2006
  2. atakan

    Asp.net SHA256 problem

    atakan, Nov 4, 2003, in forum: ASP .Net Security
    Replies:
    1
    Views:
    202
    atakan
    Nov 5, 2003
  3. Ravi Singh (UCSD)

    SHA256 C# vs FIPS 180

    Ravi Singh (UCSD), Jan 26, 2005, in forum: ASP .Net Security
    Replies:
    1
    Views:
    212
    Joe Kaplan \(MVP - ADSI\)
    Jan 27, 2005
  4. yf kuanfai
    Replies:
    9
    Views:
    297
    yf kuanfai
    Jan 27, 2011
  5. Himanshu Bharti

    sha256

    Himanshu Bharti, Feb 27, 2012, in forum: C++
    Replies:
    2
    Views:
    412
    Miles Bader
    Feb 27, 2012
Loading...

Share This Page