Best thing , I love about Python is, It has lots of inbuilt Pre-defined functions . which shorten our code by a large extend .
Hexadecimal encoding & decoding is very easy & need only few lines of in python .
Here Is Python2.7 code for Hex conversion from string ,and from Hex to string
- ##http://beginer2cs.blogspot.com
- ### Hexadecimal Encoder & decoder
- #NOTE It Convert It treat Number as string
- def Hex_encode(a):
- '''
- take string or integer as input
- &
- return hexadecimal encoded of it
- '''
- b=a.encode("hex")
- return b
- def Hex_decode(a):
- '''
- Take Hexadecimal encode
- &
- return actual value
- '''
- b=a.decode("hex")
- return b
- a = raw_input('Enter data to Encode in Hexadecimal : ') #take input
- print "\nHex_Encoded data is :",Hex_encode(a),"\n"
- c = raw_input('Enter Encoded data to decode : ') #take input
- print "\nHex_decoded data is : ",Hex_decode(c)
Output for this simple code is :
I generally used a basic shift cipher then hex encryption to to make some special comment at Facebook .such that only I and some of my friend can understand it ..
No comments:
Post a Comment
THANKS FOR UR GREAT COMMENT