Guest User

Untitled

a guest
Apr 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. fun main(args: Array<String>) {
  2.  
  3. val digest = MessageDigest.getInstance("SHA-256")
  4.  
  5. args.forEach { digest.update(it.toLowerCase().toByteArray(Charset.forName("UTF-8"))) }
  6.  
  7. println(digest.digest().toHexString())
  8. }
  9.  
  10. /**
  11. * Set of chars for a half-byte.
  12. */
  13. private val CHARS = arrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f')
  14.  
  15. /**
  16. * Returns the string of two characters representing the HEX value of the byte.
  17. */
  18. internal fun Byte.toHexString(): String {
  19. val i = this.toInt()
  20. val char2 = CHARS[i and 0x0f]
  21. val char1 = CHARS[i shr 4 and 0x0f]
  22. return "$char1$char2"
  23. }
  24.  
  25. /**
  26. * Returns the HEX representation of ByteArray data.
  27. */
  28. internal fun ByteArray.toHexString(): String {
  29. val builder = StringBuilder()
  30. for (b in this) {
  31. builder.append(b.toHexString())
  32. }
  33. return builder.toString()
  34. }
Add Comment
Please, Sign In to add comment