June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,2 +1,3 @@
|
|||
import crypto
|
||||
let hash = sha1 bytes('Ars longa, vita brevis', encoding:'ascii')
|
||||
import crypto { sha1 }
|
||||
let hash = sha1.hexdigest('Ars longa, vita brevis')
|
||||
print hash
|
||||
|
|
|
|||
|
|
@ -1,36 +1,3 @@
|
|||
pad=: ,1,(0#~512 | [: - 65 + #),(64#2)#:#
|
||||
|
||||
f=:4 :0
|
||||
'B C D'=: _32 ]\ y
|
||||
if. x < 20 do.
|
||||
(B*C)+.D>B
|
||||
elseif. x < 40 do.
|
||||
B~:C~:D
|
||||
elseif. x < 60 do.
|
||||
(B*C)+.(B*D)+.C*D
|
||||
elseif. x < 80 do.
|
||||
B~:C~:D
|
||||
end.
|
||||
)
|
||||
|
||||
K=: ((32#2) #: 16b5a827999 16b6ed9eba1 16b8f1bbcdc 16bca62c1d6) {~ <.@%&20
|
||||
|
||||
plus=:+&.((32#2)&#.)
|
||||
|
||||
H=: #: 16b67452301 16befcdab89 16b98badcfe 16b10325476 16bc3d2e1f0
|
||||
|
||||
process=:4 :0
|
||||
W=. (, [: , 1 |."#. _3 _8 _14 _16 ~:/@:{ ])^:64 x ]\~ _32
|
||||
'A B C D E'=. y=._32[\,y
|
||||
for_t. i.80 do.
|
||||
TEMP=. (5|.A) plus (t f B,C,D) plus E plus (W{~t) plus K t
|
||||
E=. D
|
||||
D=. C
|
||||
C=. 30 |. B
|
||||
B=. A
|
||||
A=. TEMP
|
||||
end.
|
||||
,y plus A,B,C,D,:E
|
||||
)
|
||||
|
||||
sha1=: [:> [: process&.>/ (<H) (,~ |.) _512<\ pad
|
||||
sha1=:128!:6
|
||||
sha1'Rosetta Code'
|
||||
48c98f7e5a6e736d790ab740dfc3f51a61abe2b5
|
||||
|
|
|
|||
|
|
@ -1,5 +1,36 @@
|
|||
text2bits=: (8#2) ,@:#: a. i. ]
|
||||
bits2hex=: '0123456789abcdef' {~ _4 #.\ ,
|
||||
pad=: ,1,(0#~512 | [: - 65 + #),(64#2)#:#
|
||||
|
||||
bits2hex sha1 text2bits 'Rosetta Code'
|
||||
48c98f7e5a6e736d790ab740dfc3f51a61abe2b5
|
||||
f=:4 :0
|
||||
'B C D'=: _32 ]\ y
|
||||
if. x < 20 do.
|
||||
(B*C)+.D>B
|
||||
elseif. x < 40 do.
|
||||
B~:C~:D
|
||||
elseif. x < 60 do.
|
||||
(B*C)+.(B*D)+.C*D
|
||||
elseif. x < 80 do.
|
||||
B~:C~:D
|
||||
end.
|
||||
)
|
||||
|
||||
K=: ((32#2) #: 16b5a827999 16b6ed9eba1 16b8f1bbcdc 16bca62c1d6) {~ <.@%&20
|
||||
|
||||
plus=:+&.((32#2)&#.)
|
||||
|
||||
H=: #: 16b67452301 16befcdab89 16b98badcfe 16b10325476 16bc3d2e1f0
|
||||
|
||||
process=:4 :0
|
||||
W=. (, [: , 1 |."#. _3 _8 _14 _16 ~:/@:{ ])^:64 x ]\~ _32
|
||||
'A B C D E'=. y=._32[\,y
|
||||
for_t. i.80 do.
|
||||
TEMP=. (5|.A) plus (t f B,C,D) plus E plus (W{~t) plus K t
|
||||
E=. D
|
||||
D=. C
|
||||
C=. 30 |. B
|
||||
B=. A
|
||||
A=. TEMP
|
||||
end.
|
||||
,y plus A,B,C,D,:E
|
||||
)
|
||||
|
||||
sha1=: [:> [: process&.>/ (<H) (,~ |.) _512<\ pad
|
||||
|
|
|
|||
5
Task/SHA-1/J/sha-1-4.j
Normal file
5
Task/SHA-1/J/sha-1-4.j
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
text2bits=: (8#2) ,@:#: a. i. ]
|
||||
bits2hex=: '0123456789abcdef' {~ _4 #.\ ,
|
||||
|
||||
bits2hex sha1 text2bits 'Rosetta Code'
|
||||
48c98f7e5a6e736d790ab740dfc3f51a61abe2b5
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
2
Task/SHA-1/Lingo/sha-1.lingo
Normal file
2
Task/SHA-1/Lingo/sha-1.lingo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
crypto = xtra("Crypto").new()
|
||||
put crypto.cx_sha1_string("Rosetta Code")
|
||||
10
Task/SHA-1/Ring/sha-1.ring
Normal file
10
Task/SHA-1/Ring/sha-1.ring
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Project : SHA-1
|
||||
# Date : 2018/05/18
|
||||
# Author : Gal Zsolt [~ CalmoSoft ~]
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
load "stdlib.ring"
|
||||
str = "Rosetta Code"
|
||||
see "String: " + str + nl
|
||||
see "SHA-1: "
|
||||
see sha1(str) + nl
|
||||
Loading…
Add table
Add a link
Reference in a new issue