python小例子之7 -- 生成md5串

主題: 生成md5串
 環境: winxp pro + sp2 + python2.5
備註: 請注意,凡是在源代碼文件中使用了中文字符,請最好保存爲utf-8格式
代碼:
python 代碼
  1. # tmd5.py   
  2. import md5  
  3. import hashlib   
  4.   
  5. src = 'this is a test.'   
  6. m1 = md5.new()   
  7. m1.update(src)   
  8. dest1 = m1.hexdigest()   
  9.   
  10. m2 = hashlib.md5()   
  11. m2.update(src)   
  12. dest2 = m2.hexdigest()   
  13.   
  14. print 'source string: ', src   
  15. print 'destination string1: ', dest1   
  16. print 'destination string2: ', dest2   
測試:保存爲文件,直接執行即可
發佈了3 篇原創文章 · 獲贊 0 · 訪問量 2759
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章