2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1 @@
PrintLn( HashSHA1.HashData('Rosetta code') );

View file

@ -0,0 +1,96 @@
module sha1_m
use kernel32
use advapi32
implicit none
integer, parameter :: SHA1LEN = 20
contains
subroutine sha1hash(name, hash, dwStatus, filesize)
implicit none
character(*) :: name
integer, parameter :: BUFLEN = 32768
integer(HANDLE) :: hFile, hProv, hHash
integer(DWORD) :: dwStatus, nRead
integer(BOOL) :: status
integer(BYTE) :: buffer(BUFLEN)
integer(BYTE) :: hash(SHA1LEN)
integer(UINT64) :: filesize
dwStatus = 0
filesize = 0
hFile = CreateFile(trim(name) // char(0), GENERIC_READ, FILE_SHARE_READ, NULL, &
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL)
if (hFile == INVALID_HANDLE_VALUE) then
dwStatus = GetLastError()
print *, "CreateFile failed."
return
end if
if (CryptAcquireContext(hProv, NULL, NULL, PROV_RSA_FULL, &
CRYPT_VERIFYCONTEXT) == FALSE) then
dwStatus = GetLastError()
print *, "CryptAcquireContext failed."
goto 3
end if
if (CryptCreateHash(hProv, CALG_SHA1, 0_ULONG_PTR, 0_DWORD, hHash) == FALSE) then
dwStatus = GetLastError()
print *, "CryptCreateHash failed."
go to 2
end if
do
status = ReadFile(hFile, loc(buffer), BUFLEN, loc(nRead), NULL)
if (status == FALSE .or. nRead == 0) exit
filesize = filesize + nRead
if (CryptHashData(hHash, buffer, nRead, 0) == FALSE) then
dwStatus = GetLastError()
print *, "CryptHashData failed."
go to 1
end if
end do
if (status == FALSE) then
dwStatus = GetLastError()
print *, "ReadFile failed."
go to 1
end if
nRead = SHA1LEN
if (CryptGetHashParam(hHash, HP_HASHVAL, hash, nRead, 0) == FALSE) then
dwStatus = GetLastError()
print *, "CryptGetHashParam failed.", status, nRead, dwStatus
end if
1 status = CryptDestroyHash(hHash)
2 status = CryptReleaseContext(hProv, 0)
3 status = CloseHandle(hFile)
end subroutine
end module
program sha1
use sha1_m
implicit none
integer :: n, m, i, j
character(:), allocatable :: name
integer(DWORD) :: dwStatus
integer(BYTE) :: hash(SHA1LEN)
integer(UINT64) :: filesize
n = command_argument_count()
do i = 1, n
call get_command_argument(i, length=m)
allocate(character(m) :: name)
call get_command_argument(i, name)
call sha1hash(name, hash, dwStatus, filesize)
if (dwStatus*0 == 0) then
do j = 1, SHA1LEN
write(*, "(Z2.2)", advance="NO") hash(j)
end do
write(*, "(' ',A,' (',G0,' bytes)')") name, filesize
end if
deallocate(name)
end do
end program

View file

@ -1,36 +1,4 @@
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
require '~addons/ide/qt/qt.ijs'
getsha1=: 'sha1'&gethash_jqtide_
getsha1 'Rosetta Code'
48c98f7e5a6e736d790ab740dfc3f51a61abe2b5

View file

@ -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

View file

@ -1,42 +1,5 @@
text2bits=: (8#2) ,@:#: a. i. ]
words2bits=: ,@:((32#2)&#:)
text2bits=: (8#2) ,@:#: a. i. ]
bits2hex=: '0123456789abcdef' {~ _4 #.\ ,
pad=: _32 #.\ (, 1,(0#~512 | [: - 65 + #),(64#2)#:#)
lim32=: 2^32
rot32=: (] lim32&|@* 2 ^ [) + ] <.@% 2 ^ 32- [
and=: 17 b.
notimplies=: 18 b.
xor=: 22 b.
or=: 23 b.
f=:4 :0
'B C D'=: y
if. x < 20 do.
(B and C) or D notimplies B
elseif. x < 40 do.
B xor C xor D
elseif. x < 60 do.
(B and C) or (B and D) or C and D
elseif. x < 80 do.
B xor C xor D
end.
)
K=: 16b5a827999 16b6ed9eba1 16b8f1bbcdc 16bca62c1d6 {~ <.@%&20
process=:3 :0
H=. 16b67452301 16befcdab89 16b98badcfe 16b10325476 16bc3d2e1f0
W=. (, [: , 1 rot32 _3 _8 _14 _16 xor/@:{ ])^:64 y
'A B C D E'=. H
for_t. i.80 do.
TEMP=. lim32|(5 rot32 A) + (t f B,C,D) + E + (W{~t) + K t
E=. D
D=. C
C=. 30 rot32 B
B=. A
A=. TEMP
end.
,lim32|H + A,B,C,D,E
)
sha1=: _16 process\ pad
bits2hex sha1 text2bits 'Rosetta Code'
48c98f7e5a6e736d790ab740dfc3f51a61abe2b5

View file

@ -0,0 +1,7 @@
a$="Rosetta Code"
UseSHA1Fingerprint() : b$=StringFingerprint(a$, #PB_Cipher_SHA1)
OpenConsole()
Print("[SHA1] Text: "+a$+" ==> "+b$)
Input()

View file

@ -0,0 +1,2 @@
require("chksum");
print(sha1sum("Rosetta Code"));

View file

@ -1,11 +1,3 @@
(define-library (lib sha1)
(export
sha1:digest)
(import (r5rs base)
(owl math) (owl list) (owl string) (owl list-extra))
(begin
; band - binary AND operation
; bor - binary OR operation
; bxor - binary XOR operation
@ -166,4 +158,3 @@
(->32 (+ C c))
(->32 (+ D d))
(->32 (+ E e)))))))))
))

View file

@ -1,4 +1,3 @@
(import (lib sha1))
(define (->string value)
(runes->string
(let ((L "0123456789abcdef"))