Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
November 16th, 2012, 01:03 PM
 Highest bidder
Registered User

Join Date: Nov 2012
Posts: 21
Time spent in forums: 5 h 37 m 15 sec
Reputation 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
November 16th, 2012, 04:41 PM
 Yegers
Registered User

Join Date: Nov 2012
Posts: 26
Time spent in forums: 12 h 7 m 8 sec
Reputation 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

#3
November 17th, 2012, 06:01 AM
 Highest bidder
Registered User

Join Date: Nov 2012
Posts: 21
Time spent in forums: 5 h 37 m 15 sec
Reputation Power: 0
Quote:
 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?

#4
November 17th, 2012, 02:11 PM
 Yegers
Registered User

Join Date: Nov 2012
Posts: 26
Time spent in forums: 12 h 7 m 8 sec
Reputation Power: 0
Code:
```>>> import binascii
>>> binascii.hexlify(b'helloworld')
b'68656c6c6f776f726c64'```

this should do the the job ^^'

Good luck Yegers

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Crypto python DES encryption with hex