Skip to content

Instantly share code, notes, and snippets.

@aboisvert
Created August 27, 2016 18:14
Show Gist options
  • Save aboisvert/52b967242cfcea3defbbbe35b741151a to your computer and use it in GitHub Desktop.
Save aboisvert/52b967242cfcea3defbbbe35b741151a to your computer and use it in GitHub Desktop.
import strutils
const SHA512Len = 64
proc SHA512(d: cstring, n: culong, md: cstring = nil): cstring {.cdecl, dynlib: "libssl.dylib", importc.}
proc SHA512(s: string): string =
result = ""
let s = SHA512(s.cstring, s.len.culong)
for i in 0 .. < SHA512Len:
result.add s[i].BiggestInt.toHex(2).toLowerAscii
echo SHA512("Rosetta code")
@aboisvert
Copy link
Author

aboisvert commented Aug 27, 2016

$ nim c -r sha512.nim
Hint: used config file '/Users/aboisver/git/nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: sha512 [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
CC: compiler_sha512
Hint:  [Link]
Hint: operation successful (14153 lines compiled; 0.217 sec total; 20.004MiB; Debug Build) [SuccessX]
Hint: /Users/aboisver/nim/sha512/sha512  [Exec]
b58ac9d50d64f2b5cd67b81482aa87b8b21ab423811134c2676e5975c45fb82aa89b87ce9fd431e97a0f6f7c85f741426c363f46e70c651a937ddb5466075d6a```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment