Thread: Crypto DES CTR

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Europe
    Posts
    21
    Rep Power
    0

    Crypto DES CTR


    with the following code:
    Code:
    from Crypto.Cipher import DES #or AES
    from Crypto.Util import Counter # or import Crypto.Util.Counter
    
    iv = 123456789
    PT = 'aaaaaaaa'
    key = 'qwer' * 2 # for des or *4 for AES
    ctr = counter(128)
    
    des = DES.new(key, DES.MODE_CTR, counter = ctr)
    print des.encrypt(PT)
    i get the following message for DES:
    TypeError: CTR counter function returned string not of length 8

    and for the AES:
    TypeError: CTR counter function returned string not of length 16

    any suggestions?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    ctr = counter(128)

    Capitalizing Counter Advances You to the Next Big Bug.

    Comments on this post

    • Highest bidder agrees
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Europe
    Posts
    21
    Rep Power
    0
    Originally Posted by b49P23TIvg
    ctr = counter(128)

    Capitalizing Counter Advances You to the Next Big Bug.
    haha perfect you mean this?:

    TypeError: 'module' object is not callable

    i have tried these:
    http://stackoverflow.com/questions/3154998/pycrypto-problem-using-aesctr

    http://stackoverflow.com/questions/12691168/how-aes-in-ctr-works-for-python-with-pycrypto

    http://stackoverflow.com/questions/11656045/pycrypto-incrementing-ctr-mode

    but non would work
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Europe
    Posts
    21
    Rep Power
    0
    no answers yet? anyway i have managed to make counter work however i still can find a way do decrypt in CTR cipher... the next time i run the program it generates a new counter (so wrong outcome) and when i try saving the counter to reuse it, it doesnt work at all and i get "callable error message"
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    Cripes, it's a holiday here in America. Yes, I meant that you'd next find that the module can't be called.

    Comments on this post

    • Highest bidder agrees
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Europe
    Posts
    21
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Cripes, it's a holiday here in America. Yes, I meant that you'd next find that the module can't be called.
    haha sorry i didnt know you were holidays anyhow, when you will be able to reply(you or some1 else): Are implying that the CTR mode(in python) has a huge bug, since the original module is not working smoothly and the CTR mode can only be used to encrypt...? is that right?
  12. #7
  13. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    I have no experience with the Crypto module. I didn't know it came with the standard distribution. With deep faith I started python, tried to import it, and met success. All I can do is about the same as you---read the documents and try the examples. My only advantage might be that I've looked at python documents more than you. Your advantage is that you know what it's supposed to do and why you might want it. You might have prior experience with DES. Heck, I struggle the few times I need to make public and private keys for secure cp, to whatever extent that experience is related.
    [code]Code tags[/code] are essential for python code and Makefiles!
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Europe
    Posts
    21
    Rep Power
    0
    Originally Posted by b49P23TIvg
    I have no experience with the Crypto module. I didn't know it came with the standard distribution. With deep faith I started python, tried to import it, and met success. All I can do is about the same as you---read the documents and try the examples. My only advantage might be that I've looked at python documents more than you. Your advantage is that you know what it's supposed to do and why you might want it. You might have prior experience with DES. Heck, I struggle the few times I need to make public and private keys for secure cp, to whatever extent that experience is related.
    i see... anyhow, thanks for your time i will run through the documentation once more, but i dont have high hopes about it...
  16. #9
  17. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,711
    Rep Power
    480
    Code:
    from Crypto.Cipher import DES
    from Crypto.Util import Counter
    
    #print(dir(Counter))
    #print(help(Counter))
    
    iv = 123456789
    PT = 'aaaaaaaa'
    key = 'qwer' * 2 # for des or *4 for AES
    ctr = Counter.new(128)################  this again advances you to the next problem
    
    des = DES.new(key, DES.MODE_CTR, counter = ctr)
    print des.encrypt(PT)
    I reiterate that I have no clue where you're going. I can't think forward to the next step. I can't understand why there are bad people who make encryption necessary.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo