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

    Join Date
    Nov 2012
    Location
    Europe
    Posts
    21
    Rep Power
    0

    Crypto python DES encryption with hex


    i want to make a program that encrypts and decrypts. Because it is too big i wont post it but only the interesting code:

    Code:
    pt = str(input_txt) # has to be multiple of 8
    key = str(input_key) # must be 8 bytes long
    
    des = DES.new(key, DES.MODE_ECB)
    
    chiper_txt = des.encrypt(input_txt)
    my problem is that this code produces symbols, while i want to make it produce hexadecimal numbers. how can i do it? (for both input and output)
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    26
    Rep Power
    0
    a method to convert decimal numbers to hexadecimal:

    Code:
    dec = input()
    print(int(hex(dec))))
    
    #use hex(dec)[2:] to remove "0x" etc.
    helps?

    Yegers
  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 Yegers
    a method to convert decimal numbers to hexadecimal:

    Code:
    dec = input()
    print(int(hex(dec))))
    
    #use hex(dec)[2:] to remove "0x" etc.
    helps?

    Yegers
    i already knew that but it wont help if the outcome is string ad not a number... any other suggestions?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    26
    Rep Power
    0
    Code:
    >>> import binascii
    >>> binascii.hexlify(b'helloworld')
    b'68656c6c6f776f726c64'
    this should do the the job ^^'

    Good luck Yegers

IMN logo majestic logo threadwatch logo seochat tools logo