June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,39 +1,12 @@
|
|||
using Nettle
|
||||
|
||||
function sha1sum(s::String)
|
||||
bytes2hex(sha1_hash(s))
|
||||
testdict = Dict("abc" => "a9993e364706816aba3e25717850c26c9cd0d89d",
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" =>
|
||||
"84983e441c3bd26ebaae4aa1f95129e5e54670f1",
|
||||
"a" ^ 1_000_000 => "34aa973cd4c4daa4f61eeb2bdbad27316534016f",)
|
||||
|
||||
for (text, expect) in testdict
|
||||
digest = hexdigest("sha1", text)
|
||||
if length(text) > 50 text = text[1:50] * "..." end
|
||||
println("# $text\n -> digest: $digest\n -> expect: $expect")
|
||||
end
|
||||
|
||||
println("Testing SHA-1 function against FIPS 180-1")
|
||||
|
||||
s = sha1sum("abc")
|
||||
t = lowercase("A9993E364706816ABA3E25717850C26C9CD0D89D")
|
||||
print(" \"abc\" should yield ", t)
|
||||
if s == t
|
||||
println(", and it does.")
|
||||
else
|
||||
println(", but it yields ", s)
|
||||
end
|
||||
|
||||
s = sha1sum("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
|
||||
t = lowercase("84983E441C3BD26EBAAE4AA1F95129E5E54670F1")
|
||||
print(" \"abcdbc...\" should yield ", t)
|
||||
if s == t
|
||||
println(", and it does.")
|
||||
else
|
||||
println(", but it yields ", s)
|
||||
end
|
||||
|
||||
s = sha1sum("a"^10^6)
|
||||
t = lowercase("34AA973CD4C4DAA4F61EEB2BDBAD27316534016F")
|
||||
print(" a million \"a\"s should yield ", t)
|
||||
if s == t
|
||||
println(", and it does.")
|
||||
else
|
||||
println(", but it yields ", s)
|
||||
end
|
||||
|
||||
println("\nAlso")
|
||||
s = "Rosetta Code"
|
||||
h = sha1sum(s)
|
||||
println(" ", s, " => ", h)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue