python encyption

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
#coding:utf-8
import sys
import math
import hashlib
encylist={
         1:"md5",
         2:"sha1",
         3:"sha224",
         4:"sha256",
         5:"sha384"
     }
def dojob(getvalue,encyvalue):
 if encyvalue =="md5":
     value=hashlib.md5()
     value.update(getvalue)
     return value.hexdigest()
 elif encyvalue =="sha1":
     value=hashlib.sha1()
     value.update(getvalue)
     return value.hexdigest()
 elif encyvalue=="sha224":
     value=hashlib.sha224()
     value.update(getvalue)
     return value.hexdigest()
 elif encyvalue=="sha384":
      value=hashlib.sha384()
      value.update(getvalue)
      return value.hexdigest()
 else:
      value=hashlib.sha256()
      value.update(getvalue)
      return value.hexdigest()
if __name__=="__main__":
      teststring=raw_input("put a string to encypt:\n")
      try:
        print """
        1:md5 , 2:sha1 , 3:sha224 ,4:sha256 ,5:sha384
        """
        encytype=int(math.floor(float(raw_input("input your encyption type:"))))
        assert(1<=encytype<=5)
        print dojob(teststring,encylist[encytype])
      except ValueError:
        print "choose right number !"
      except AssertionError:
        print "numbers not in the range listed above! "

Test

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Kerwin at February 10, 2014 - 8:29 PM