TEXT   119
MD5Hash
Guest on 8th March 2023 12:40:12 AM


  1. /* MD5Hash
  2.  */
  3.  
  4. package main
  5.  
  6. import (
  7.         "crypto/md5"
  8.         "fmt"
  9. )
  10.  
  11. func main() {
  12.         hash := md5.New()
  13.         bytes := []byte("hello\n")
  14.         hash.Write(bytes)
  15.         hashValue := hash.Sum(nil)
  16.         hashSize := hash.Size()
  17.         for n := 0; n < hashSize; n += 4 {
  18.                 var val uint32
  19.                 val = uint32(hashValue[n])<<24 +
  20.                         uint32(hashValue[n+1])<<16 +
  21.                         uint32(hashValue[n+2])<<8 +
  22.                         uint32(hashValue[n+3])
  23.                 fmt.Printf("%x ", val)
  24.         }
  25.         fmt.Println()
  26. }

Raw Paste

Login or Register to edit or fork this paste. It's free.