Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
52
Task/MD4/AutoHotkey/md4.ahk
Normal file
52
Task/MD4/AutoHotkey/md4.ahk
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
str := "Rosetta Code"
|
||||
MsgBox, % "String:`n" (str) "`n`nMD4:`n" MD4(str)
|
||||
|
||||
|
||||
|
||||
; MD4 ===============================================================================
|
||||
MD4(string, encoding = "utf-8")
|
||||
{
|
||||
return CalcStringHash(string, 0x8002, encoding)
|
||||
}
|
||||
|
||||
; CalcAddrHash ======================================================================
|
||||
CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0)
|
||||
{
|
||||
static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"]
|
||||
static b := h.minIndex()
|
||||
o := ""
|
||||
if (DllCall("advapi32\CryptAcquireContext", "Ptr*", hProv, "Ptr", 0, "Ptr", 0, "UInt", 24, "UInt", 0xF0000000))
|
||||
{
|
||||
if (DllCall("advapi32\CryptCreateHash", "Ptr", hProv, "UInt", algid, "UInt", 0, "UInt", 0, "Ptr*", hHash))
|
||||
{
|
||||
if (DllCall("advapi32\CryptHashData", "Ptr", hHash, "Ptr", addr, "UInt", length, "UInt", 0))
|
||||
{
|
||||
if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", 0, "UInt*", hashlength, "UInt", 0))
|
||||
{
|
||||
VarSetCapacity(hash, hashlength, 0)
|
||||
if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", &hash, "UInt*", hashlength, "UInt", 0))
|
||||
{
|
||||
loop, % hashlength
|
||||
{
|
||||
v := NumGet(hash, A_Index - 1, "UChar")
|
||||
o .= h[(v >> 4) + b] h[(v & 0xf) + b]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DllCall("advapi32\CryptDestroyHash", "Ptr", hHash)
|
||||
}
|
||||
DllCall("advapi32\CryPtreleaseContext", "Ptr", hProv, "UInt", 0)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
; CalcStringHash ====================================================================
|
||||
CalcStringHash(string, algid, encoding = "utf-8", byref hash = 0, byref hashlength = 0)
|
||||
{
|
||||
chrlength := (encoding = "cp1200" || encoding = "utf-16") ? 2 : 1
|
||||
length := (StrPut(string, encoding) - 1) * chrlength
|
||||
VarSetCapacity(data, length, 0)
|
||||
StrPut(string, &data, floor(length / chrlength), encoding)
|
||||
return CalcAddrHash(&data, length, algid, hash, hashlength)
|
||||
}
|
||||
7
Task/MD4/Emacs-Lisp/md4.l
Normal file
7
Task/MD4/Emacs-Lisp/md4.l
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(require 'md4)
|
||||
(let* ((s "Rosetta Code")
|
||||
(m (md4 s (length s)))) ;; m = 16 binary bytes
|
||||
(require 'hex-util)
|
||||
(encode-hex-string m))
|
||||
=>
|
||||
"a52bcfc6a0d0d300cdc5ddbfbefe478b"
|
||||
7
Task/MD4/Seed7/md4.seed7
Normal file
7
Task/MD4/Seed7/md4.seed7
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "msgdigest.s7i";
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
writeln(hex(md4("Rosetta Code")));
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue