Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. I get different results from the Linux command "sha256sum" and the Pony stdlib "Digest" functions.
  2.  
  3. Using the command line:
  4. echo "123456" | sha256sum
  5. e150a1ec81e8e93e1eae2c3a77e66ec6dbd6a3b460f89c1d08aecf422ee401a0 -
  6.  
  7. Using the Pony program shown below:
  8. sha256 of '123456' is 8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
  9.  
  10.  
  11. use "crypto"
  12.  
  13. actor Main
  14. new create( env: Env ) =>
  15. let input = "123456"
  16. let hasher = Digest.sha256()
  17. try hasher.append( input ) end
  18. let binhash = hasher.final()
  19. // Convert the binary hash to a hex string. We know the length
  20. // will be twice as long so we can preallocate enough space.
  21. let hexhash = String( binhash.size()*2 )
  22. var i: USize = 0
  23. while i < binhash.size() do
  24. let byte = try binhash(i) else 0 end
  25. hexhash.push( _hexdigit((byte and 0xF0 ) >> 4))
  26. hexhash.push( _hexdigit( byte and 0x0F ))
  27. i = i + 1
  28. end
  29. env.out.print("sha256 of '"+input+"' is "+hexhash)
  30.  
  31. fun ref _hexdigit( n: U8 ): U8 =>
  32. try "0123456789abcdef"(n.usize()) else '0' end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement