#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! "
测试可以