September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -9,20 +9,20 @@ Function RIPEMD_160(message As String) As String
|
|||
|
||||
#Macro f1(x, y, z)
|
||||
(x Xor y Xor z) ' (0 <= j <= 15)
|
||||
|
||||
#EndMacro
|
||||
|
||||
#Macro f2(x, y, z)
|
||||
((x And y) Or ((Not x) And z)) ' (16 <= j <= 31)
|
||||
|
||||
#EndMacro
|
||||
|
||||
#Macro f3(x, y, z)
|
||||
((x Or (Not y)) Xor z) ''(32 <= j <= 47)
|
||||
|
||||
#EndMacro
|
||||
|
||||
#Macro f4(x, y, z)
|
||||
((x And z) Or (y And (Not z))) ''(48 <= j <= 63)
|
||||
|
||||
#EndMacro
|
||||
|
||||
#Macro f5(x, y, z)
|
||||
(x Xor (y Or (Not z))) ''(64 <= j <= 79)
|
||||
#EndMacro
|
||||
|
|
@ -172,7 +172,6 @@ Dim As String test = "Rosetta Code"
|
|||
Print
|
||||
Print test; " => "; RIPEMD_160(test)
|
||||
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
|
|
|
|||
8
Task/RIPEMD-160/PARI-GP/ripemd-160-3.pari
Normal file
8
Task/RIPEMD-160/PARI-GP/ripemd-160-3.pari
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
install(RIPEMD160,"vsLs",,"/usr/lib/x86_64-linux-gnu/libcrypto.so")
|
||||
ripemd160(a)=
|
||||
{
|
||||
my(b=Strchr(vectorsmall(20,i,32)));
|
||||
RIPEMD160(a,length(a),b);
|
||||
Strprintf("%x",fromdigits(Vec(Vecsmall(b)),256));
|
||||
}
|
||||
ripemd160("Rosetta Code")
|
||||
|
|
@ -42,16 +42,16 @@ constant F =
|
|||
{ ($^x +& $^z) +| ($^y +& m^$^z) },
|
||||
* +^ (* +| m^*),
|
||||
;
|
||||
constant K1 = <0x00000000 0x5a827999 0x6ed9eba1 0x8f1bbcdc 0xa953fd4e> »xx» 16;
|
||||
constant K2 = <0x50a28be6 0x5c4dd124 0x6d703ef3 0x7a6d76e9 0x00000000> »xx» 16;
|
||||
constant K1 = flat | <0x00000000 0x5a827999 0x6ed9eba1 0x8f1bbcdc 0xa953fd4e> »xx» 16;
|
||||
constant K2 = flat | <0x50a28be6 0x5c4dd124 0x6d703ef3 0x7a6d76e9 0x00000000> »xx» 16;
|
||||
|
||||
our proto rmd160($) returns Blob {*}
|
||||
multi rmd160(Str $s) { rmd160 $s.encode: 'ascii' }
|
||||
multi rmd160(Blob $data) {
|
||||
my @b = $data.list, 0x80;
|
||||
my @b = | $data, 0x80;
|
||||
push @b, 0 until (8*@b-448) %% 512;
|
||||
my $len = 8 * $data.elems;
|
||||
push @b, gather for ^8 { take $len % 256; $len div= 256 }
|
||||
push @b, | gather for ^8 { take $len % 256; $len div= 256 }
|
||||
|
||||
my @word = gather for @b -> $a, $b, $c, $d {
|
||||
take reduce * *256 + *, $d, $c, $b, $a;
|
||||
|
|
@ -62,17 +62,15 @@ multi rmd160(Blob $data) {
|
|||
my @X = my @Y = @h;
|
||||
for ^80 -> $j {
|
||||
my $T = rotl(
|
||||
@X[0] m+ F[$j div 16](|@X[1..3]) m+ (@word[$i+r1[$j]] // 0) m+ K1[$j],
|
||||
s1[$j]
|
||||
@X[0] m+ F[$j div 16](|@X[1..3]) m+ (@word[$i+r1[$j]] // 0) m+ K1[$j], s1[$j]
|
||||
) m+ @X[4];
|
||||
@X = @X[4], $T, @X[1], rotl(@X[2], 10) % 2**32, @X[3];
|
||||
$T = rotl(
|
||||
@Y[0] m+ F[(79-$j) div 16](|@Y[1..3]) m+ (@word[$i+r2[$j]] // 0) m+ K2[$j],
|
||||
s2[$j]
|
||||
@Y[0] m+ F[(79-$j) div 16](|@Y[1..3]) m+ (@word[$i+r2[$j]] // 0) m+ K2[$j], s2[$j]
|
||||
) m+ @Y[4];
|
||||
@Y = @Y[4], $T, @Y[1], rotl(@Y[2], 10) % 2**32, @Y[3];
|
||||
}
|
||||
@h = @h[1..4,^1] Z[m+] @X[2..4,^2] Z[m+] @Y[3..4,^3];
|
||||
@h = (flat @h[1..4,^1]) Z[m+] (flat @X[2..4,^2]) Z[m+] flat @Y[3..4,^3];
|
||||
}
|
||||
return Blob.new: gather for @h -> $word is rw {
|
||||
for ^4 { take $word % 256; $word div= 256 }
|
||||
|
|
|
|||
51
Task/RIPEMD-160/PowerShell/ripemd-160-1.psh
Normal file
51
Task/RIPEMD-160/PowerShell/ripemd-160-1.psh
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
function Get-Hash
|
||||
{
|
||||
[CmdletBinding(DefaultParameterSetName="String")]
|
||||
[OutputType([string])]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true,
|
||||
ParameterSetName="String",
|
||||
Position=0)]
|
||||
[string]
|
||||
$String,
|
||||
|
||||
[Parameter(Mandatory=$true,
|
||||
ParameterSetName="FileName",
|
||||
Position=0)]
|
||||
[string]
|
||||
$FileName,
|
||||
|
||||
[Parameter(Mandatory=$false,
|
||||
Position=1)]
|
||||
[ValidateSet("MD5", "RIPEMD160", "SHA1", "SHA256", "SHA384", "SHA512")]
|
||||
[string]
|
||||
$HashType = "MD5"
|
||||
)
|
||||
|
||||
$hashAlgorithm = [System.Security.Cryptography.HashAlgorithm]
|
||||
$stringBuilder = New-Object -TypeName System.Text.StringBuilder
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName)
|
||||
{
|
||||
"String"
|
||||
{
|
||||
$hashAlgorithm::Create($HashType).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String)) | ForEach-Object {
|
||||
$stringBuilder.Append($_.ToString("x2")) | Out-Null
|
||||
}
|
||||
}
|
||||
"FileName"
|
||||
{
|
||||
$fileStream = New-Object -TypeName System.IO.FileStream -ArgumentList $FileName, ([System.IO.FileMode]::Open)
|
||||
|
||||
$hashAlgorithm::Create($HashType).ComputeHash($fileStream) | ForEach-Object {
|
||||
$stringBuilder.Append($_.ToString("x2")) | Out-Null
|
||||
}
|
||||
|
||||
$fileStream.Close()
|
||||
$fileStream.Dispose()
|
||||
}
|
||||
}
|
||||
|
||||
$stringBuilder.ToString()
|
||||
}
|
||||
1
Task/RIPEMD-160/PowerShell/ripemd-160-2.psh
Normal file
1
Task/RIPEMD-160/PowerShell/ripemd-160-2.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
Get-Hash "Rosetta Code" -HashType RIPEMD160
|
||||
2
Task/RIPEMD-160/Zkl/ripemd-160.zkl
Normal file
2
Task/RIPEMD-160/Zkl/ripemd-160.zkl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var MsgHash=Import("zklMsgHash");
|
||||
MsgHash.RIPEMD160("Rosetta Code")
|
||||
Loading…
Add table
Add a link
Reference in a new issue