Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: modexp

  1. #1
    h4x Guest

    modexp

    i have to write rsa enc/dec.


    Keys are 100% corrext. Why it doesnt work?
    Code:
    def modexp ( t, u, n ):
       s = 1
       while u:
        	if u & 1:
        	   s = (s * t)%n
        	u >>= 1
        	t = (t * t)%n;
       return s
       
       
       
       
    a = 0x61616161616161616161
       
       
    a = modexp(a, 65537, 109120132967399429278860960508995541528237502902798129123468757937266291492576446330739696001110603907230888610072655818825358503429057592827629436413108566029093628212635953836686562675849720620786279431090218017681061521755056710823876476444260558147179707119674283982419152118103759076030616683978566631413);
    a = modexp(a, 65537, 46730330223584118622160180015036832148732986808519344675210555262940258739805766860224610646919605860206328024326703361630109888417839241959507572247284807035235569619173792292786907845791904955103601652822519121908367187885509270025388641700821735345222087940578381210879116823013776808975766851829020659073);
    
    
    
    print(hex(a));

  2. CODECALL Circuit advertisement

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,486
    Blog Entries
    75
    Rep Power
    143

    Re: modexp

    What is it doing? Also, I think your algorithm may be flawed.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    h4x Guest

    Re: modexp

    its rsa encryption and decryption.
    it should print 0x61616161... but instead im betting another value.

    where is the flow in my algoritm?
    please help me ;/

  5. #4
    h4x Guest

    Re: modexp

    pow() and % give also same result (encryption), decryption is so slow that i interrupted test. so i dont think my algo is flawed.

  6. #5
    Join Date
    Jul 2006
    Posts
    16,486
    Blog Entries
    75
    Rep Power
    143

    Re: modexp

    Usually, RSA doesn't require % until AFTER the while loop. Using % at each round of the loop is almost guaranteed to hose your results.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  7. #6
    h4x Guest

    Re: modexp

    huh?
    how does modulo after each round destroy result?

    and without modulo i dont think i have enought memory to process that
    i managed to finilize pow() method - same result as modexp both enc and dec.

    Code:
    def modexp ( t, u, n ):
       s = 1
       while u:
        	if u & 1:
        	   s = (s * t)
        	u >>= 1
        	t = (t * t)
       return s%n
       
       
       
       
    a = 0x6161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161
       
       
    a = modexp(a, 65537, 109120132967399429278860960508995541528237502902798129123468757937266291492576446330739696001110603907230888610072655818825358503429057592827629436413108566029093628212635953836686562675849720620786279431090218017681061521755056710823876476444260558147179707119674283982419152118103759076030616683978566631413);
    a = modexp(a, 65537, 46730330223584118622160180015036832148732986808519344675210555262940258739805766860224610646919605860206328024326703361630109888417839241959507572247284807035235569619173792292786907845791904955103601652822519121908367187885509270025388641700821735345222087940578381210879116823013776808975766851829020659073);
    
    
    
    print(hex(a));
    doesnt work, still executing and i doubt it will finish.

  8. #7
    Join Date
    Jul 2006
    Posts
    16,486
    Blog Entries
    75
    Rep Power
    143

    Re: modexp

    I stand corrected on the %. Why are you using a >>= operator, though? You aren't getting the power 65537 in that case.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  9. #8
    h4x Guest

    Re: modexp

    look: my algo is fine. exactly SAME result if using pow(a, 65537)%4234232....
    but bilion times faster
    >>= is to properly process only bits wich are 1. next step t*t % n change each step, so if exponent is

    101

    it will be
    *1
    *1^3

    or smth like that.
    if you can please generate your own rsa keys somewere and test it.

    i stuck in this for... hmm i think it will be 1 month soon.
    HELP

  10. #9
    h4x Guest

    Re: modexp

    ohdave.com/rsa/


    im getting right cipher value, but it seems i cant obtain deciphered bessage after

  11. #10
    Join Date
    Jul 2006
    Posts
    16,486
    Blog Entries
    75
    Rep Power
    143

    Re: modexp

    Your message is:
    a = 0x616161616161616161616161616161616161616161616161 61616161616161616161616161616161616161616161616161 61616161616161616161616161616161616161616161616161 61616161616161616161616161616161616161616161616161 61616161616161616161616161616161616161616161616161 61616161

    You encrypt the message by calling encrypted = message^e mod n
    You decrypt the message by calling message = encrypted^d mod n

    However, based on what I can see, you are not doing that, you are doing:
    You encrypt the message by calling encrypted = message^n mod e
    You decrypt the message by calling message = encrypted^n mod d
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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