RIPEMD-160: Difference between revisions

87,485 bytes added ,  3 months ago
m
m (→‎{{header|Wren}}: Minor tidy)
 
(38 intermediate revisions by 18 users not shown)
Line 13:
Use the ASCII encoded string “<tt>Rosetta Code</tt>”.
You may either call an RIPEMD-160 library, or implement RIPEMD-160 in your language.
 
=={{header|Ada}}==
{{libheader|CryptAda}}
<syntaxhighlight lang="ada">with Ada.Text_IO;
 
with CryptAda.Pragmatics;
with CryptAda.Digests.Message_Digests.RIPEMD_160;
with CryptAda.Digests.Hashes;
with CryptAda.Utils.Format;
 
procedure RC_RIPEMD_160 is
use CryptAda.Pragmatics;
use CryptAda.Digests.Message_Digests;
use CryptAda.Digests;
 
function To_Byte_Array (Item : String) return Byte_Array is
Result : Byte_Array (Item'Range);
begin
for I in Result'Range loop
Result (I) := Byte (Character'Pos (Item (I)));
end loop;
return Result;
end To_Byte_Array;
 
Text : constant String := "Rosetta Code";
Bytes : constant Byte_Array := To_Byte_Array (Text);
Handle : constant Message_Digest_Handle := RIPEMD_160.Get_Message_Digest_Handle;
Pointer : constant Message_Digest_Ptr := Get_Message_Digest_Ptr (Handle);
Hash : Hashes.Hash;
begin
Digest_Start (Pointer);
Digest_Update (Pointer, Bytes);
Digest_End (Pointer, Hash);
 
Ada.Text_IO.Put_Line
("""" & Text & """: " & CryptAda.Utils.Format.To_Hex_String (Hashes.Get_Bytes (Hash)));
end RC_RIPEMD_160;</syntaxhighlight>
{{out}}
<pre>"Rosetta Code": B3BE159860842CEBAA7174C8FFF0AA9E50A5199F</pre>
 
=={{header|C}}==
The original implementation of RIPEMD-160 was in C. I edited [https://homes.esat.kuleuven.be/~bosselae/ripemd160/ps/AB-9601/hashtest.c hashtest.c] to include [https://homes.esat.kuleuven.be/~bosselae/ripemd160/ps/AB-9601/rmd160.c rmd160.c] or [https://homes.esat.kuleuven.be/~bosselae/ripemd160/ps/AB-9601/rmd128.c rmd128.c] depending on the value of the macro, RMDsize as shown below :
 
<syntaxhighlight lang="c">
#ifndef RMDsize
#define RMDsize 160
#endif
 
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#if RMDsize == 128
#include "rmd128.h"
#include "rmd128.c" /* Added to remove errors during compilation */
#elif RMDsize == 160
#include "rmd160.h"
#include "rmd160.c" /* Added to remove errors during compilation */
#endif
 
</syntaxhighlight>
The test strings used in every example are included in [https://homes.esat.kuleuven.be/~bosselae/ripemd160/ps/AB-9601/hashtest.c hashtest.c]. Compilation produces a warning as the return type of main is not explicitly defined.
 
<pre>
pi@raspberrypi:~/doodles $ cc hashtest.c
hashtest.c:298:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
main (int argc, char *argv[])
^~~~
</pre>
Invocation without any arguments produces the usage message :
<pre>
pi@raspberrypi:~/doodles $ ./a.out
For each command line argument in turn:
filename -- compute hash code of file binary read
-sstring -- print string & hashcode
-t -- perform time trial
-x -- execute standard test suite, ASCII input
</pre>
 
The -t and -x flags, taken together or separately hash the strings with performance data :
<pre>
pi@raspberrypi:~/doodles $ ./a.out -x
 
 
RIPEMD-160 test suite results (ASCII):
 
* message: "" (empty string)
hashcode: 9c1185a5c5e9fc54612808977ee8f548b2258d31
* message: "a"
hashcode: 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe
* message: "abc"
hashcode: 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
* message: "message digest"
hashcode: 5d0689ef49d2fae572b881b123a85ffa21595f36
* message: "abcdefghijklmnopqrstuvwxyz"
hashcode: f71c27109c692c1b56bbdceb5b9d2865b3708dbc
* message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
hashcode: 12a053384a9c0c88e405a06c27dcf49ada62eb2b
* message: "A...Za...z0...9"
hashcode: b0e20b6e3116640286ed3a87a5713079b21f5189
* message: 8 times "1234567890"
hashcode: 9b752e45573d4b39f4dbd3323cab82bf63326bfb
* message: 1 million times "a"
hashcode: 52783243c1697bdbe16d37f97f68f08325dc1528
 
pi@raspberrypi:~/doodles $ ./a.out -t
 
 
RIPEMD-160 time trial. Processing 10000000 characters...
 
Test input processed in 0.440118 seconds.
Characters processed per second: 2.27212e+07
 
hashcode: 48e29b3b6fd12e61d8a2e5e0c92652c988cc83ea
 
pi@raspberrypi:~/doodles $ ./a.out -t -x
 
 
RIPEMD-160 time trial. Processing 10000000 characters...
 
Test input processed in 0.440054 seconds.
Characters processed per second: 2.27245e+07
 
hashcode: 393813510b7db924f9a9979a732ed7435be29dd4
 
 
RIPEMD-160 test suite results (ASCII):
 
* message: "" (empty string)
hashcode: 9c1185a5c5e9fc54612808977ee8f548b2258d31
* message: "a"
hashcode: 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe
* message: "abc"
hashcode: 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
* message: "message digest"
hashcode: 5d0689ef49d2fae572b881b123a85ffa21595f36
* message: "abcdefghijklmnopqrstuvwxyz"
hashcode: f71c27109c692c1b56bbdceb5b9d2865b3708dbc
* message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
hashcode: 12a053384a9c0c88e405a06c27dcf49ada62eb2b
* message: "A...Za...z0...9"
hashcode: b0e20b6e3116640286ed3a87a5713079b21f5189
* message: 8 times "1234567890"
hashcode: 9b752e45573d4b39f4dbd3323cab82bf63326bfb
* message: 1 million times "a"
hashcode: 52783243c1697bdbe16d37f97f68f08325dc1528
 
 
</pre>
 
And yes, all of this was done on a Raspberry Pi 4B with 4 GB RAM, which I suspect is more powerful than the system(s) on which RIPEMD-160 was initially designed and tested.
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
using System.Security.Cryptography;
using System.Text;
Line 31 ⟶ 182:
Console.ReadLine();
}
}</langsyntaxhighlight>
{{out}}
<pre>b3be159860842cebaa7174c8fff0aa9e50a5199f</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <bit>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <stdexcept>
#include <sstream>
#include <string>
#include <vector>
 
class RIPEMD160 {
public:
std::string message_digest(const std::string& message) {
std::vector<int64_t> state = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 };
 
std::vector<uint8_t> bytes = add_padding(message);
for ( uint64_t i = 0; i < bytes.size() / BLOCK_LENGTH; ++i ) {
std::vector<uint32_t> schedule(16, 0);
for ( uint32_t j = 0; j < BLOCK_LENGTH; ++j ) {
schedule[j / 4] |= ( bytes[i + j] ) << ( j % 4 * 8 );
}
 
int32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4];
int32_t aa = state[0], bb = state[1], cc = state[2], dd = state[3], ee = state[4];
int32_t t = 0, tt = 0;
 
for ( uint32_t j = 0; j < 80; ++j ) {
uint32_t jj = j / 16;
t = std::rotl(a + ff(jj + 1, b, c, d) + schedule[RL[j]] + KL[jj], SL[j]) + e;
tt = std::rotl(aa + ff(5 - jj, bb, cc, dd) + schedule[RR[j]] + KR[jj], SR[j]) + ee;
 
a = e; e = d; d = std::rotl(static_cast<uint32_t>(c), 10); c = b; b = t;
aa = ee; ee = dd; dd = std::rotl(static_cast<uint32_t>(cc), 10); cc = bb; bb = tt;
}
 
t = state[1] + c + dd;
state[1] = state[2] + d + ee;
state[2] = state[3] + e + aa;
state[3] = state[4] + a + bb;
state[4] = state[0] + b + cc;
state[0] = t;
}
 
std::stringstream stream;
for ( uint32_t i = 0; i < state.size() * 4; ++i ) {
int8_t byte_value = static_cast<int8_t>(unsigned_right_shift(state[i / 4], i % 4 * 8));
stream << std::setfill('0') << std::setw(2) << std::hex << ( byte_value & 0xff );
}
return stream.str();
}
 
private:
std::vector<uint8_t> add_padding(const std::string& message) {
std::vector<uint8_t> bytes(message.begin(), message.end());
bytes.emplace_back(static_cast<uint8_t>(0x80));
 
uint32_t padding = BLOCK_LENGTH - ( bytes.size() % BLOCK_LENGTH );
if ( padding < 8 ) {
padding += BLOCK_LENGTH;
}
bytes.resize(bytes.size() + padding - 8, static_cast<uint8_t>(0x0));
 
const uint64_t bit_length = 8 * message.length();
for ( uint32_t i = 0; i < 8; ++i ) {
bytes.emplace_back(static_cast<uint8_t>( bit_length >> ( 8 * i ) ));
}
return bytes;
}
 
uint32_t ff(const uint32_t& group, const uint32_t& x, const uint32_t& y, const uint32_t& z) {
uint32_t result;
switch ( group ) {
case 1: result = x ^ y ^ z; break;
case 2: result = ( x & y ) | ( ~x & z ); break;
case 3: result = ( x | ~y ) ^ z; break;
case 4: result = ( x & z ) | ( y & ~z ); break;
case 5: result = x ^ ( y | ~z ); break;
default: throw std::invalid_argument("Unexpected argument: " + group);
};
return result;
}
 
int32_t unsigned_right_shift(const int32_t& base, const int32_t& shift) {
if ( shift < 0 || shift >= 32 ) {
throw std::invalid_argument("Shift must be in range 0..31: " + shift);
}
if ( base == 0 ) {
return 0;
}
return ( base > 0 ) ? base >> shift : static_cast<uint32_t>(base) >> shift;
}
 
const std::vector<uint32_t> SR = { 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 };
 
const std::vector<uint32_t> SL = { 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 };
 
const std::vector<uint32_t> RR = { 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 };
 
const std::vector<uint32_t> RL = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 };
 
const std::vector<uint32_t> KL = { 0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e };
const std::vector<uint32_t> KR = { 0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000 };
 
const uint32_t BLOCK_LENGTH = 64;
};
 
int main() {
RIPEMD160 ripemd160;
std::cout << ripemd160.message_digest("Rosetta Code") << std::endl;
}
</syntaxhighlight>
{{ out }}
<pre>
b3be159860842cebaa7174c8fff0aa9e50a5199f
</pre>
 
=={{header|Clojure}}==
{{libheader|pandect}}
<langsyntaxhighlight lang="clojure">(use 'pandect.core)
(ripemd160 "Rosetta Code")</langsyntaxhighlight>
 
{{Out}}
Line 45 ⟶ 329:
=={{header|Common Lisp}}==
{{libheader|Ironclad}}
<langsyntaxhighlight lang="lisp">(ql:quickload 'ironclad)
(defun string-to-ripemd-160 (str)
"Return the RIPEMD-160 digest of the given ASCII string."
Line 52 ⟶ 336:
(ironclad:ascii-string-to-byte-array str)))
 
(string-to-ripemd-160 "Rosetta Code")</langsyntaxhighlight>
 
{{out}}
Line 58 ⟶ 342:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.digest.ripemd;
 
writefln("%(%02x%)", "Rosetta Code".ripemd160Of);
}</langsyntaxhighlight>
{{out}}
<pre>b3be159860842cebaa7174c8fff0aa9e50a5199f</pre>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| DCPripemd160}}
<syntaxhighlight lang="delphi">
program RIPEMD160;
 
{$APPTYPE CONSOLE}
 
uses
System.SysUtils,
DCPripemd160;
 
function HashRipemd160(const Input: Ansistring): TArray<byte>;
var
Hasher: TDCP_ripemd160;
begin
Hasher := TDCP_ripemd160.Create(nil);
try
Hasher.Init;
Hasher.UpdateStr(Input);
SetLength(Result, Hasher.HashSize div 8);
Hasher.final(Result[0]);
finally
Hasher.Free;
end;
end;
 
begin
for var b in HashRipemd160('Rosetta Code') do
begin
write(b.ToHexString(2));
end;
readln;
end.</syntaxhighlight>
{{out}}
<pre>B3BE159860842CEBAA7174C8FFF0AA9E50A5199F</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.98}}
<syntaxhighlight lang="factor">USING: checksums checksums.ripemd io math.parser ;
 
"Rosetta Code" ripemd-160 checksum-bytes bytes>hex-string print</syntaxhighlight>
{{out}}
<pre>
b3be159860842cebaa7174c8fff0aa9e50a5199f
</pre>
 
=={{header|Fortran}}==
{{works with|Fortran|2003}}
 
<syntaxhighlight lang="fortran">program main
use, intrinsic :: iso_c_binding
implicit none
 
integer, parameter :: DIGEST_LEN = 20
integer, parameter :: HASH_LEN = 40
 
interface
function c_ripemd160(d, n, md) bind(c, name='RIPEMD160')
import :: c_char, c_long, c_ptr
implicit none
character(kind=c_char), intent(in) :: d
integer(kind=c_long), intent(in), value :: n
character(kind=c_char), intent(in) :: md
type(c_ptr) :: c_ripemd160
end function c_ripemd160
end interface
 
print '(a)', ripemd160('Rosetta Code')
contains
function ripemd160(str) result(hash)
character(len=*), intent(in) :: str
character(len=HASH_LEN) :: hash
 
character(len=DIGEST_LEN) :: raw
integer :: i
type(c_ptr) :: ptr
 
hash = ' '
ptr = c_ripemd160(str, len(str, kind=c_long), raw)
if (.not. c_associated(ptr)) return
write (hash, '(20z2.2)') (raw(i:i), i = 1, DIGEST_LEN)
end function ripemd160
end program main</syntaxhighlight>
 
{{out}}
<pre>B3BE159860842CEBAA7174C8FFF0AA9E50A5199F</pre>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 22-10-2016
' compile with: fbc -s console
 
Line 244 ⟶ 616:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre>Rosetta Code => b3be159860842cebaa7174c8fff0aa9e50a5199f</pre>
Line 250 ⟶ 622:
=={{header|Go}}==
{{libheader|Go sub-repositories}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 261 ⟶ 633:
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}</langsyntaxhighlight>
{{out}}
<pre>
b3be159860842cebaa7174c8fff0aa9e50a5199f
</pre>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Char (ord)
import Crypto.Hash.RIPEMD160 (hash)
import Data.ByteString (unpack, pack)
Line 279 ⟶ 652:
map (fromIntegral.ord) -- to array of Word8
"Rosetta Code"
</syntaxhighlight>
</lang>
{{out}}
<pre style="font-size:80%">b3be159860842cebaa7174c8fff0aa9e50a5199f
</pre>
 
=={{header|Java}}==
{{libheader|BouncyCastle}}
<langsyntaxhighlight lang="java">import org.bouncycastle.crypto.digests.RIPEMD160Digest;
import org.bouncycastle.util.encoders.Hex;
 
Line 300 ⟶ 674:
System.out.println();
}
}</langsyntaxhighlight>
{{out}}
<pre>
b3be159860842cebaa7174c8fff0aa9e50a5199f
</pre>
 
===Without external libraries===
<syntaxhighlight lang="java">
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
 
public final class RIPEMD160Task {
 
public static void main(String[] aArgs) {
System.out.println(RIPEMD160.messageDigest("Rosetta Code"));
}
 
}
 
final class RIPEMD160 {
public static String messageDigest(String aMessage) {
int[] state = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 };
byte[] bytes = addPadding(aMessage);
for ( int i = 0; i < bytes.length / BLOCK_LENGTH; i++ ) {
int[] schedule = new int[16];
for ( int j = 0; j < BLOCK_LENGTH; j++ ) {
schedule[j / 4] |= ( bytes[i * BLOCK_LENGTH + j] & 0xff ) << ( j % 4 * 8 );
}
int a = state[0], b = state[1], c = state[2], d = state[3], e = state[4];
int aa = state[0], bb = state[1], cc = state[2], dd = state[3], ee = state[4];
int t = 0, tt = 0;
for ( int j = 0; j < 80; j++ ) {
int jj = j / 16;
t = Integer.rotateLeft(a + ff(jj + 1, b, c, d) + schedule[RL[j]] + KL[jj], SL[j]) + e;
tt = Integer.rotateLeft(aa + ff(5 - jj, bb, cc, dd) + schedule[RR[j]] + KR[jj], SR[j]) + ee;
a = e; e = d; d = Integer.rotateLeft(c, 10); c = b; b = t;
aa = ee; ee = dd; dd = Integer.rotateLeft(cc, 10); cc = bb; bb = tt;
}
t = state[1] + c + dd;
state[1] = state[2] + d + ee;
state[2] = state[3] + e + aa;
state[3] = state[4] + a + bb;
state[4] = state[0] + b + cc;
state[0] = t;
}
String result = "";
for ( int i = 0; i < state.length * 4; i++ ) {
result += String.format("%02x", (byte) ( state[i / 4] >>> ( i % 4 * 8 ) ));
}
return result;
}
private static byte[] addPadding(String aMessage) {
byte[] bytes = aMessage.getBytes(StandardCharsets.UTF_8);
bytes = Arrays.copyOf(bytes, bytes.length + 1);
bytes[bytes.length - 1] = (byte) 0x80;
int padding = BLOCK_LENGTH - ( bytes.length % BLOCK_LENGTH );
if ( padding < 8 ) {
padding += BLOCK_LENGTH;
}
bytes = Arrays.copyOf(bytes, bytes.length + padding);
final long bitLength = aMessage.length() * 8;
for ( int i = 0; i < 8; i++ ) {
bytes[bytes.length - 8 + i] = (byte) ( bitLength >>> ( 8 * i ) );
}
return bytes;
}
private static int ff(int aGroup, int aX, int aY, int aZ) {
return switch ( aGroup ) {
case 1 -> aX ^ aY ^ aZ;
case 2 -> ( aX & aY ) | ( ~aX & aZ );
case 3 -> ( aX | ~aY ) ^ aZ;
case 4 -> ( aX & aZ ) | ( aY & ~aZ );
case 5 -> aX ^ ( aY | ~aZ );
default -> throw new IllegalArgumentException("Unexpected argument: " + aGroup);
};
}
private static final int[] KL = new int[] { 0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e };
private static final int[] KR = new int [] { 0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000 };
private static final int[] RL = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 };
private static final int[] RR = new int[] { 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 };
private static final int[] SL = new int[] { 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 };
private static final int[] SR = new int[] { 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 };
private static final int BLOCK_LENGTH = 64;
}
</syntaxhighlight>
{{ out }}
<pre>
b3be159860842cebaa7174c8fff0aa9e50a5199f
Line 309 ⟶ 801:
{{works with|Julia|0.6}}
 
<langsyntaxhighlight lang="julia">using Nettle
 
labels = ["\"\" (empty string)", "\"a\"", "\"abc\"",
Line 332 ⟶ 824:
digest = hexdigest("ripemd160", text)
println("# $lab\n -> digest: $digest\n -> expect: $expect")
end</langsyntaxhighlight>
 
{{out}}
Line 365 ⟶ 857:
=={{header|Kotlin}}==
{{libheader|BouncyCastle}}
<langsyntaxhighlight lang="scala">import org.bouncycastle.crypto.digests.RIPEMD160Digest
import org.bouncycastle.util.encoders.Hex
import kotlin.text.Charsets.US_ASCII
Line 384 ⟶ 876:
Hex.encode(output, System.out)
System.out.flush()
}</langsyntaxhighlight>
{{out}}
<pre>
Line 391 ⟶ 883:
 
=={{header|Lasso}}==
<langsyntaxhighlight lang="lasso">
cipher_digest("Rosetta Code", -digest='RIPEMD160', -hex)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 404 ⟶ 896:
{{libheader|LuaCrypto}} luarocks install LuaCrypto (see mkottman dot github dot io slash luacrypto; I am getting fed up with reCAPTCHA)
 
<langsyntaxhighlight Lualang="lua">#!/usr/bin/lua
 
require "crypto"
 
print(crypto.digest("ripemd160", "Rosetta Code"))</langsyntaxhighlight>
 
{{out}}
<pre>b3be159860842cebaa7174c8fff0aa9e50a5199f</pre>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Module Checkit {
Function Prepare_RiPeMd_160 {
Dim Base 0, K(5), K1(5)
K(0)=0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E
K1(0)=0x50A28BE6,0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000
Dim Base 0,r(80), r1(80), s(80), s1(80)
r(0)=0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
r(16)=7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8
r(32)= 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12
r(48)=1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2
r(64)=4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
k=r() : k*=4 ' k is a pointer to array. We have to multiply to make them offsets
r1(0)=5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12
r1(16)=6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2
r1(32)=15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13
r1(48)=8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14
r1(64)=12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
k=r1() : k*=4
s(0)=11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8
s(16)=7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12
s(32)=11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5
s(48)=11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12
s(64)=9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
s1(0)=8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6
s1(16)=9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11
s1(32)=9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5
s1(48)=15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8
s1(64)=8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
Dim Base 0, T(5), TT(5)
T(0)=lambda ->binary.xor(binary.xor(number,number),number)
T(1)=lambda (B,C,D)->binary.or(binary.and(B,C), binary.and(binary.not(B), D))
T(2)=lambda ->binary.xor(binary.or(number, binary.not(number)), number)
T(3)=lambda (B,C,D)->binary.or(binary.and(B,D), binary.and(C,binary.not(D)))
T(4)=lambda ->binary.xor(number, binary.or(number, binary.not(number)))
\\ no need for variables we read form stack with number
TT(0)=lambda ->binary.xor(number, binary.or(number, binary.not(number)))
TT(1)=lambda (BB,CC,DD)->binary.or(binary.and(BB,DD), binary.and(CC,binary.not(DD)))
TT(2)=lambda ->binary.xor(binary.or(number, binary.not(number)), number)
TT(3)=lambda (BB,CC,DD)->binary.or(binary.and(BB,CC), binary.and(binary.not(BB),DD))
TT(4)=lambda ->binary.xor(binary.xor(number,number),number)
\\ return of this function is a lambda function
\\ all arrays are closures to this lambda
=lambda K(),K1(),TT(), T(),r(),r1(), s(), s1() (&message$, ansi as boolean=true, ansiid=1033)-> {
set fast!
def h0 = 0x67452301, h1 = 0xEFCDAB89, h2 = 0x98BADCFE
def h3 = 0x10325476, h4 = 0xC3D2E1F0
def i, j, l, padding, l1, blocks, acc, f64 as boolean=true, oldid
if ansi then oldid=locale : locale ansiid
\\ we use a buffer of 64 bytes
buffer clear message as byte*64
l=len(message$)*if(ansi->1,2 )
if binary.and(l,63)>55 then padding=64
padding+= 64 - (l Mod 64)
l1=padding+l+1
f64=binary.and(l,63)<>0
blocks=l1 div 64
rem
Print "blocks:";blocks
\\ now prepare the buffer
PrepareBuffer()
def decimal A, B, C, D, E, AA, BB, CC, DD, EE, T, TT
do
A = h0 : B = h1 : C = h2 : D = h3 : E = h4
AA = h0 : BB = h1 : CC = h2 : DD = h3 : EE = h4
for J=0 to 79 {
JJ=J DIV 16
PUSH binary.add(Binary.Rotate(binary.add(A,T(JJ)(B,C,D),eval(message ,r(j) as long),k(jj)), s(j)), e)
A = E : E = D : D = Binary.Rotate(C, 10) : C = B : READ B
PUSH binary.add(Binary.Rotate(binary.add(AA,TT(JJ)(BB,CC,DD),eval(message, r1(j) as long),k1(jj)),s1(j)),EE)
AA = EE : EE = DD : DD = Binary.Rotate(CC, 10) : CC = BB : READ BB
}
push binary.add(h1, C, DD)
h1 = binary.add(h2, D, EE)
h2 = binary.add(h3, E, AA)
h3 = binary.add(h4, A, BB)
h4 = binary.add(h0, B, CC)
Read h0
blocks--
rem
print over $(0,8), blocks : Refresh
if blocks=0 then exit
PrepareBuffer()
always
rem
print
buffer ans as byte*20
\\ we put ulong (long is ulong in buffers)
Return ans, 0:=h0 as long, 4:=h1 as long,8:=h2 as long, 12:=h3 as long, 16:=h4 as long
=ans
if ansi then locale oldid
set fast
Sub PrepareBuffer()
if l-acc>=64 then
LoadPart(64)
else.if blocks=1 then
return message, 0:=string$(chr$(0),32)
if l-acc=0 and f64 then
Return message, 56:=l*8 as long, 60 :=binary.shift(l,-29) as long
else
Return message, l-acc:=0x80, 56:=l*8 as long, 60 :=binary.shift(l,-29) as long
if l>acc then LoadPart(l-acc)
end if
else
Return message, l-acc:=0x80
LoadPart(l-acc)
end if
End Sub
sub LoadPart(many)
\\ str$() convert to ansi, one byte per character
\\ using 1033 as Ansi language
if ansi then
Return message, 0:=str$(mid$(message$,1+acc, many))
else
Return message, 0:=mid$(message$, 1+acc, many)
end if
acc+=many
end sub
}
}
Module TestHash (RIPEMD){
Flush
\\ push data to stack of values, as fifo (each entry append to end of stack)
Data "b3be159860842cebaa7174c8fff0aa9e50a5199f","Rosetta Code"
Data "9c1185a5c5e9fc54612808977ee8f548b2258d31",""
Data "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe","a"
Data "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc","abc"
Data "5d0689ef49d2fae572b881b123a85ffa21595f36", "message digest"
Data "f71c27109c692c1b56bbdceb5b9d2865b3708dbc","abcdefghijklmnopqrstuvwxyz"
Data "b0e20b6e3116640286ed3a87a5713079b21f5189"
Data "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
Data "9b752e45573d4b39f4dbd3323cab82bf63326bfb", String$("1234567890",8)
rem Data "52783243c1697bdbe16d37f97f68f08325dc1528", String$("a",1000000)
While not empty
Read check$, text$
Print "RIPEMD160 for ";quote$(Left$(if$(len(text$)>30->left$(text$,27)+"...", text$),30))
\\ pass text$ by reference
Display(RIPEMD(&text$))
End While
sub Display(ans)
local answer$
for i=0 to len(ans)-1
answer$+=hex$(eval(ans,i),1)
next i
Print lcase$(answer$)
Print lcase$(answer$)=check$
end sub
}
TestHash Prepare_RiPeMd_160()
}
Checkit
</syntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="text">Hash["Rosetta Code", "RIPEMD160", "HexString"]</syntaxhighlight>
{{out}}
<pre>b3be159860842cebaa7174c8fff0aa9e50a5199f</pre>
 
=={{header|Nim}}==
 
{{libheader|nimcrypto|0.5.4}}
{{works with|Nim Compiler|1.4.4}}
 
<syntaxhighlight lang="nim">import nimcrypto / [ripemd, hash]
 
echo ripemd160.digest("Rosetta Code")</syntaxhighlight>
 
{{out}}
<pre>B3BE159860842CEBAA7174C8FFF0AA9E50A5199F</pre>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
class Hash {
function : Main(args : String[]) ~ Nil {
Line 422 ⟶ 1,097:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>B3BE159860842CEBAA7174C8FFF0AA9E50A5199F</pre>
Line 430 ⟶ 1,105:
Build RIPEMD-160 plugin using Linux system library and PARI's function interface.
 
<langsyntaxhighlight Clang="c">#include <pari/pari.h>
#include <openssl/ripemd.h>
 
Line 451 ⟶ 1,126:
 
return strtoGENstr(hash);
}</langsyntaxhighlight>
 
Compile with: ''gcc -Wall -O2 -fPIC -shared ripemd160.c -o libripemd160.so -lcrypto -lpari''
 
Load plugin from your home directory into PARI:
<langsyntaxhighlight lang="parigp">install("plug_ripemd160", "s", "RIPEMD160", "~/libripemd160.so");
 
RIPEMD160("Rosetta Code")</langsyntaxhighlight>
 
Output: <pre>"b3be159860842cebaa7174c8fff0aa9e50a5199f"</pre>
Line 464 ⟶ 1,139:
It can also be done in GP with an install hack (thanks to Bill Allombert for this code):
 
<langsyntaxhighlight lang="parigp">install(RIPEMD160,"vsLs",,"/usr/lib/x86_64-linux-gnu/libcrypto.so")
ripemd160(a)=
{
Line 471 ⟶ 1,146:
Strprintf("%x",fromdigits(Vec(Vecsmall(b)),256));
}
ripemd160("Rosetta Code")</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use Crypt::RIPEMD160;
say unpack "H*", Crypt::RIPEMD160->hash("Rosetta Code");</langsyntaxhighlight>
{{out}}
<pre>b3be159860842cebaa7174c8fff0aa9e50a5199f</pre>
 
The [https://metacpan.org/release/CryptX CryptX] module also implements RIPEMD-160 along with the 128-, 256-, and 320-bit variants, as well many many other hashes. This gives identical output as above as expected.
<langsyntaxhighlight lang="perl">use Crypt::Digest::RIPEMD160 qw/ripemd160_hex/;
say ripemd160_hex("Rosetta Code")</langsyntaxhighlight>
 
=={{header|Perl 6}}==
<lang perl6>=for CREDITS
Crypto-JS v2.0.0
http:#code.google.com/p/crypto-js/
Copyright (c) 2009, Jeff Mott. All rights reserved.
sub rotl($n, $b) { $n +< $b +| $n +> (32 - $b) }
sub prefix:<m^> { +^$^x % 2**32 }
sub infix:<m+> { ($^x + $^y) % 2**32 }
constant r1 = <
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
7 4 13 1 10 6 15 3 12 0 9 5 2 14 11 8
3 10 14 4 9 15 8 1 2 7 0 6 13 11 5 12
1 9 11 10 0 8 12 4 13 3 7 15 14 5 6 2
4 0 5 9 7 12 2 10 14 1 3 8 11 6 15 13
>;
constant r2 = <
5 14 7 0 9 2 11 4 13 6 15 8 1 10 3 12
6 11 3 7 0 13 5 10 14 15 8 12 4 9 1 2
15 5 1 3 7 14 6 9 11 8 12 2 10 0 4 13
8 6 4 1 3 11 15 0 5 12 2 13 9 7 10 14
12 15 10 4 1 5 8 7 6 2 13 14 0 3 9 11
>;
constant s1 = <
11 14 15 12 5 8 7 9 11 13 14 15 6 7 9 8
7 6 8 13 11 9 7 15 7 12 15 9 11 7 13 12
11 13 6 7 14 9 13 15 14 8 13 6 5 12 7 5
11 12 14 15 14 15 9 8 9 14 5 6 8 6 5 12
9 15 5 11 6 8 13 12 5 12 13 14 11 8 5 6
>;
constant s2 = <
8 9 9 11 13 15 15 5 7 7 8 11 14 14 12 6
9 13 15 7 12 8 9 11 7 7 12 7 6 15 13 11
9 7 15 11 8 6 6 14 12 13 5 14 13 13 7 5
15 5 8 11 14 14 6 14 6 9 12 9 12 5 15 8
8 5 12 9 12 5 14 6 8 13 6 5 15 13 11 11
>;
constant F =
* +^ * +^ *,
{ ($^x +& $^y) +| (m^$^x +& $^z) },
(* +| m^*) +^ *,
{ ($^x +& $^z) +| ($^y +& m^$^z) },
* +^ (* +| m^*),
;
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, 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 }
my @word = gather for @b -> $a, $b, $c, $d {
take reduce * *256 + *, $d, $c, $b, $a;
}
my @h = 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0;
loop (my $i = 0; $i < @word; $i += 16) {
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]
) 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]
) m+ @Y[4];
@Y = @Y[4], $T, @Y[1], rotl(@Y[2], 10) % 2**32, @Y[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 }
}
}
say rmd160 "Rosetta Code";</lang>
 
{{Out}}
<pre>Buf:0x<b3 be 15 98 60 84 2c eb aa 71 74 c8 ff f0 aa 9e 50 a5 19 9f></pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">-->
<lang Phix>include builtins\ripemd160.e
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">ripemd160</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
 
constant test = "Rosetta Code"
<span style="color: #008080;">constant</span> <span style="color: #000000;">test</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Rosetta Code"</span>
printf(1,"\n%s => %s\n",{test,ripemd160(test)})</lang>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n%s =&gt; %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">test</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ripemd160</span><span style="color: #0000FF;">(</span><span style="color: #000000;">test</span><span style="color: #0000FF;">)})</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 578 ⟶ 1,170:
</pre>
The standard include file ripemd160.e is also written in Phix, and is reproduced below.
<!--<syntaxhighlight lang="phix">-->
<lang Phix>--
<span style="color: #000080;font-style:italic;">--
-- builtins\ripemd160.e
-- builtins\ripemd160.e
-- ====================
-- ====================
--
--</span>
function rol(atom v, integer n)
<span style="color: #008080;">function</span> <span style="color: #000000;">rol</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">v</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
-- Programming note: this use of #ilASM{} is more for expediency than efficiency
<span style="color: #000080;font-style:italic;">-- Programming note: this use of #ilASM{} is more for expediency than efficiency</span>
#ilASM{ mov eax,[v]
#ilASM{ mov eax,[v]
call :%pLoadMint
mov ecx,[n]call :%pLoadMint
rol eaxmov ecx,cl[n]
lea edirol eax,[v]cl
call :%pStoreMintlea }edi,[v]
call :%pStoreMint }
return v
<span style="color: #008080;">return</span> <span style="color: #000000;">v</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
 
constant K = {#00000000,#5A827999,#6ED9EBA1,#8F1BBCDC,#A953FD4E},
<span style="color: #008080;">constant</span> <span style="color: #000000;">K</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">#00000000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#5A827999</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#6ED9EBA1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#8F1BBCDC</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#A953FD4E</span><span style="color: #0000FF;">},</span>
KK = {#50A28BE6,#5C4DD124,#6D703EF3,#7A6D76E9,#00000000},
<span style="color: #000000;">KK</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">#50A28BE6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#5C4DD124</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#6D703EF3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#7A6D76E9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#00000000</span><span style="color: #0000FF;">},</span>
r = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
<span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span>
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
<span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span>
3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
<span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span>
1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
<span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span>
4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 },
<span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span> <span style="color: #0000FF;">},</span>
rr = { 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
<span style="color: #000000;">rr</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span>
6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
<span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span>
15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
<span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span>
8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
<span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span>
12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 },
<span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span> <span style="color: #0000FF;">},</span>
s = {11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span>
7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
<span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span>
11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
<span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span>
11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
<span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span>
9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 },
<span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span> <span style="color: #0000FF;">},</span>
ss = { 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
<span style="color: #000000;">ss</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span>
9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
<span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span>
9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
<span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span>
15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
<span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span>
8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 }
<span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">11</span> <span style="color: #0000FF;">}</span>
 
global function ripemd160(string message, bool asString=true, atom pMem=NULL)
--
-- Calculate the ripe-md-160 checksum.
--
-- if asString is true (the default), returns a string representation of the
-- checksum (and pMem is ignored)
-- if asString is false, returns pMem (for want of anything better), which
-- must be a non-NULL pointer to at least 20 bytes of memory.
--
atom h0 = #67452301,
h1 = #EFCDAB89,
h2 = #98BADCFE,
h3 = #10325476,
h4 = #C3D2E1F0,
mraw, t, tt
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #000000;">ripemd160</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">message</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">asString</span><span style="color: #0000FF;">=</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">pMem</span><span style="color: #0000FF;">=</span><span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span>
integer l = length(message),
<span style="color: #000080;font-style:italic;">--
padding = 64 - mod(l+1,64)
-- Calculate the ripe-md-160 checksum.
if padding<8 then padding += 64 end if
--
 
-- if asString is true (the default), returns a string representation of the
message &= #80 & repeat('\0',padding-8)
-- checksum (and pMem is ignored)
& int_to_bytes(l*8,8)
-- if asString is false, returns pMem (for want of anything better), which
 
-- must be a non-NULL pointer to at least 20 bytes of memory.
#ilASM{ mov eax,[message]
-- </span>
lea edi,[mraw]
<span style="color: #004080;">atom</span> <span style="color: #000000;">h0</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">#67452301</span><span style="color: #0000FF;">,</span>
shl eax,2 -- ref -> raw address
<span style="color: #000000;">h1</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">#EFCDAB89</span><span style="color: #0000FF;">,</span>
call :%pStoreMint }
<span style="color: #000000;">h2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">#98BADCFE</span><span style="color: #0000FF;">,</span>
 
<span style="color: #000000;">h3</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">#10325476</span><span style="color: #0000FF;">,</span>
for i=0 to length(message)-64 by 64 do
<span style="color: #000000;">h4</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">#C3D2E1F0</span><span style="color: #0000FF;">,</span>
atom {a, b, c, d, e} = {h0, h1, h2, h3, h4}
<span style="color: #000000;">mraw</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">tt</span>
atom {aa, bb, cc, dd, ee} = {h0, h1, h2, h3, h4}
for j = 1 to 80 do
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">message</span><span style="color: #0000FF;">),</span>
integer k = floor((j-1)/16)
<span style="color: #000000;">padding</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">64</span> <span style="color: #0000FF;">-</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">64</span><span style="color: #0000FF;">)</span>
switch k
<span style="color: #008080;">if</span> <span style="color: #000000;">padding</span><span style="color: #0000FF;"><</span><span style="color: #000000;">8</span> <span style="color: #008080;">then</span> <span style="color: #000000;">padding</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">64</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
case 0:
t = xor_bits(xor_bits(b, c), d)
<span style="color: #000000;">message</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">#80</span> <span style="color: #0000FF;">&</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'\0'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">padding</span><span style="color: #0000FF;">-</span><span style="color: #000000;">8</span><span style="color: #0000FF;">)</span>
tt = xor_bits(bb,or_bits(cc,not_bits(dd)))
<span style="color: #0000FF;">&</span> <span style="color: #7060A8;">int_to_bytes</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">*</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">)</span>
case 1:
t = or_bits(and_bits(b,c),and_bits(not_bits(b),d))
#ilASM{ mov eax,[message]
tt = or_bits(and_bits(bb,dd),and_bits(cc,not_bits(dd)))
lea case 2:edi,[mraw]
shl eax,2 -- ref -&gt; raw t = xor_bits(or_bits(b,not_bits(c)),d)address
call :%pStoreMint }
tt = xor_bits(or_bits(bb,not_bits(cc)),dd)
case 3:
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">message</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">64</span> <span style="color: #008080;">by</span> <span style="color: #000000;">64</span> <span style="color: #008080;">do</span>
t = or_bits(and_bits(b,d),and_bits(c,not_bits(d)))
<span style="color: #004080;">atom</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">e</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">h0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h4</span><span style="color: #0000FF;">}</span>
tt = or_bits(and_bits(bb,cc),and_bits(not_bits(bb),dd))
<span style="color: #004080;">atom</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">aa</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">bb</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cc</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dd</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">ee</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">h0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h4</span><span style="color: #0000FF;">}</span>
case 4:
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">80</span> <span style="color: #008080;">do</span>
t = xor_bits(b,or_bits(c,not_bits(d)))
<span style="color: #004080;">integer</span> <span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">((</span><span style="color: #000000;">j</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">16</span><span style="color: #0000FF;">)</span>
tt = xor_bits(xor_bits(bb, cc), dd)
<span style="color: #008080;">switch</span> <span style="color: #000000;">k</span>
end switch
<span style="color: #008080;">case</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">:</span>
t = rol( a + t + peek4u(mraw+i+ r[j]*4) + K[k+1], s[j]) + e
<span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">xor_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xor_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">)</span>
tt = rol(aa + tt + peek4u(mraw+i+rr[j]*4) + KK[k+1], ss[j]) + ee
<span style="color: #000000;">tt</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">xor_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bb</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">or_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cc</span><span style="color: #0000FF;">,</span><span style="color: #000000;">not_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">)))</span>
{a, e, d, c, b } = {e, d, rol(c, 10), b, t }
<span style="color: #008080;">case</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">:</span>
{aa,ee,dd,cc,bb} = {ee,dd,rol(cc, 10),bb,tt}
<span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">or_bits</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">and_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">and_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">not_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b</span><span style="color: #0000FF;">),</span><span style="color: #000000;">d</span><span style="color: #0000FF;">))</span>
end for
<span style="color: #000000;">tt</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">or_bits</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">and_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bb</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">and_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cc</span><span style="color: #0000FF;">,</span><span style="color: #000000;">not_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">)))</span>
{h0, h1, h2, h3, h4} = {h1+c+dd, h2+d+ee, h3+e+aa, h4+a+bb, h0+b+cc}
<span style="color: #008080;">case</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">:</span>
end for
<span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">xor_bits</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">or_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b</span><span style="color: #0000FF;">,</span><span style="color: #000000;">not_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">)),</span><span style="color: #000000;">d</span><span style="color: #0000FF;">)</span>
if not asString then
<span style="color: #000000;">tt</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">xor_bits</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">or_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bb</span><span style="color: #0000FF;">,</span><span style="color: #000000;">not_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cc</span><span style="color: #0000FF;">)),</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">)</span>
if pMem=NULL then ?9/0 end if
<span style="color: #008080;">case</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">:</span>
poke4(pMem,{h0,h1,h2,h3,h4})
<span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">or_bits</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">and_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">and_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">,</span><span style="color: #000000;">not_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">)))</span>
return pMem
<span style="color: #000000;">tt</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">or_bits</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">and_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bb</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cc</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">and_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">not_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bb</span><span style="color: #0000FF;">),</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">))</span>
end if
<span style="color: #008080;">case</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">:</span>
atom mem = allocate(20,true)
<span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">xor_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">or_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">,</span><span style="color: #000000;">not_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">)))</span>
poke4(mem,{h0,h1,h2,h3,h4})
<span style="color: #000000;">tt</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">xor_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xor_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bb</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cc</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">dd</span><span style="color: #0000FF;">)</span>
string res = ""
<span style="color: #008080;">end</span> <span style="color: #008080;">switch</span>
for i=1 to 20 do
<span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">rol</span><span style="color: #0000FF;">(</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">t</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">peek4u</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mraw</span><span style="color: #0000FF;">+</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]*</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">K</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">])</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">e</span>
res &= sprintf("%02X",peek(mem+i-1))
<span style="color: #000000;">tt</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">rol</span><span style="color: #0000FF;">(</span><span style="color: #000000;">aa</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">tt</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">peek4u</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mraw</span><span style="color: #0000FF;">+</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">rr</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]*</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">KK</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">ss</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">])</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">ee</span>
end for
<span style="color: #0000FF;">{</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">e</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">b</span> <span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">e</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">rol</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">t</span> <span style="color: #0000FF;">}</span>
return res
<span style="color: #0000FF;">{</span><span style="color: #000000;">aa</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ee</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cc</span><span style="color: #0000FF;">,</span><span style="color: #000000;">bb</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">ee</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rol</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cc</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">),</span><span style="color: #000000;">bb</span><span style="color: #0000FF;">,</span><span style="color: #000000;">tt</span><span style="color: #0000FF;">}</span>
end function</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">h0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h4</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">h1</span><span style="color: #0000FF;">+</span><span style="color: #000000;">c</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dd</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h2</span><span style="color: #0000FF;">+</span><span style="color: #000000;">d</span><span style="color: #0000FF;">+</span><span style="color: #000000;">ee</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h3</span><span style="color: #0000FF;">+</span><span style="color: #000000;">e</span><span style="color: #0000FF;">+</span><span style="color: #000000;">aa</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h4</span><span style="color: #0000FF;">+</span><span style="color: #000000;">a</span><span style="color: #0000FF;">+</span><span style="color: #000000;">bb</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h0</span><span style="color: #0000FF;">+</span><span style="color: #000000;">b</span><span style="color: #0000FF;">+</span><span style="color: #000000;">cc</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">asString</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">pMem</span><span style="color: #0000FF;">=</span><span style="color: #004600;">NULL</span> <span style="color: #008080;">then</span> <span style="color: #0000FF;">?</span><span style="color: #000000;">9</span><span style="color: #0000FF;">/</span><span style="color: #000000;">0</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">poke4</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pMem</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">h0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">h1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">h2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">h3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">h4</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">pMem</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">mem</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">allocate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">20</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">poke4</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mem</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">h0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">h1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">h2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">h3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">h4</span><span style="color: #0000FF;">})</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">20</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">&=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%02X"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">peek</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mem</span><span style="color: #0000FF;">+</span><span style="color: #000000;">i</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<!--</syntaxhighlight>-->
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="lisp">(de *R160-R1 . (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
8 5 14 2 11 7 16 4 13 1 10 6 3 15 12 9
4 11 15 5 10 16 9 2 3 8 1 7 14 12 6 13
Line 847 ⟶ 1,441:
'(NIL (20)) ) ) ) ) )
 
(bye)</langsyntaxhighlight>
 
=={{header|PowerShell}}==
Using .Net's <code>[System.Security.Cryptography.HashAlgorithm]</code>, hash either a string or a file using any of the cryptography hash algorithms.
<syntaxhighlight lang="powershell">
<lang PowerShell>
function Get-Hash
{
Line 903 ⟶ 1,497:
$stringBuilder.ToString()
}
</syntaxhighlight>
</lang>
 
<syntaxhighlight lang="powershell">
<lang PowerShell>
Get-Hash "Rosetta Code" -HashType RIPEMD160
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 914 ⟶ 1,508:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import hashlib
Line 921 ⟶ 1,515:
>>> h.hexdigest()
'b3be159860842cebaa7174c8fff0aa9e50a5199f'
>>> </langsyntaxhighlight>
 
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket
(require (planet soegaard/digest:1:2/digest))
(ripemd160 #"Rosetta Code")
</syntaxhighlight>
</lang>
{{out}}
<langsyntaxhighlight lang="racket">
"b3be159860842cebaa7174c8fff0aa9e50a5199f"
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line># https://github.com/grondilu/libdigest-raku/blob/master/lib/Digest/RIPEMD.rakumod
 
say rmd160 "Rosetta Code";
 
=begin CREDITS
Crypto-JS v2.0.0
http:#code.google.com/p/crypto-js/
Copyright (c) 2009, Jeff Mott. All rights reserved.
=end CREDITS
 
proto rmd160($) returns Blob is export {*}
multi rmd160(Str $str) { samewith $str.encode }
multi rmd160(Blob $data) {
 
sub rotl(uint32 $n, $b) { $n +< $b +| $n +> (32 - $b) }
 
blob8.new:
map |*.polymod(256 xx 3),
|reduce
-> blob32 $h, @words {
blob32.new: [Z+] map {$_[[^5].rotate(++$)]}, $h, |await
map -> [&f, $r, @K, $s] {
start {
reduce -> $A, $j {
$A[4],
rotl(
($A[0] + (BEGIN [
* +^ * +^ *,
{ $^x +& $^y +| +^$x +& $^z },
(* +| +^*) +^ *,
{ $^x +& $^z +| $^y +& +^$^z },
{ $^x +^ ($^y +| +^$^z) }
])[&f($j) div 16](|$A[1..3])
+ @words[$r[$j]] + @K[$j]) mod 2**32,
$s[$j]
) + $A[4],
$A[1],
rotl($A[2], 10),
$A[3]
}, $h, |^80
}
},
BEGIN Array.new:
map -> [ &a,$b,@c,$d ] {
[&a,.($b),(flat @c »xx» 16),.($d)] given *.comb».parse-base(16)
},
( +*,
"0123456789ABCDEF74D1A6F3C0952EB83AE49F812706DB5C19BA08C4D37FE56240597C2AE138B6FD",
<0x00000000 0x5a827999 0x6ed9eba1 0x8f1bbcdc 0xa953fd4e>,
"BEFC5879BDEF6798768DB97F7CF9B7DCBD67E9DFE8D65C75BCEFEF989E56865C9F5B68DC5CDEB856"
),
(79-*,
"5E7092B4D6F81A3C6B370D5AEF8C4912F5137E69B8C2A04D86413BF05C2D97AECFA4158762DE039B",
<0x50a28be6 0x5c4dd124 0x6d703ef3 0x7a6d76e9 0x00000000>,
"899BDFF5778BEEC69DF7C89B77C76FDB97FB866ECD5EDD75F58BEE6E69C9C5F885C9C5E68D65FDBB"
)
;
},
(BEGIN blob32.new: 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0),
|blob32.new(
blob8.new(
$data.list,
0x80,
0 xx (-($data.elems + 1 + 8) % 64),
|(8 * $data).polymod: 256 xx 7
).rotor(4).map: { :256[@^x.reverse] }
).rotor(16);
}</syntaxhighlight>
 
{{Out}}
<pre>Buf:0x<b3 be 15 98 60 84 2c eb aa 71 74 c8 ff f0 aa 9e 50 a5 19 9f></pre>
 
=={{header|Ruby}}==
Use 'digest' from Ruby's standard library.
 
<langsyntaxhighlight lang="ruby">require 'digest'
puts Digest::RMD160.hexdigest('Rosetta Code')</langsyntaxhighlight>
 
Use 'openssl' from Ruby's standard library.
 
<langsyntaxhighlight lang="ruby">require 'openssl'
puts OpenSSL::Digest::RIPEMD160.hexdigest('Rosetta Code')</langsyntaxhighlight>
 
Implement RIPEMD-160 in Ruby.
 
<langsyntaxhighlight lang="ruby">require 'stringio'
 
module RMD160
Line 1,065 ⟶ 1,733:
str = 'Rosetta Code'
printf "%s:\n %s\n", str, *RMD160.rmd160(str).unpack('H*')
end</langsyntaxhighlight>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">
use ripemd160::{Digest, Ripemd160};
 
/// Create a lowercase hexadecimal string using the
/// RIPEMD160 hashing algorithm
fn ripemd160(text: &str) -> String {
// create a lowercase hexadecimal string
// using the shortand for the format macro
// https://doc.rust-lang.org/std/fmt/trait.LowerHex.html
format!("{:x}", Ripemd160::digest(text.as_bytes()))
}
 
fn main() {
println!("{}", ripemd160("Rosetta Code"));
}
</syntaxhighlight>
{{out}}
<pre>
b3be159860842cebaa7174c8fff0aa9e50a5199f
</pre>
 
 
=={{header|Scala}}==
{{libheader|bcprov-jdk15on-150.jar}}
<langsyntaxhighlight Scalalang="scala">import org.bouncycastle.crypto.digests.RIPEMD160Digest
 
object RosettaRIPEMD160 extends App {
Line 1,078 ⟶ 1,769:
assert(out.map("%02x".format(_)).mkString == "b3be159860842cebaa7174c8fff0aa9e50a5199f")
}</langsyntaxhighlight>
 
=={{header|Seed7}}==
The Seed7 library [http://seed7.sourceforge.net/libraries/msgdigest.htm msgdigest.s7i] defines
the function [http://seed7.sourceforge.net/libraries/msgdigest.htm#ripemd160(in_var_string) ripemd160],
which computes a RIPEMD-160 message digest. No external library is needed.
The source code of ripemd160 can be found [http://seed7.sourceforge.net/algorith/msgdigest.htm#ripemd160 here].
 
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "msgdigest.s7i";
 
const proc: main is func
begin
writeln(hex(ripemd160("Rosetta Code")));
end func;</syntaxhighlight>
 
{{out}}
<pre>
b3be159860842cebaa7174c8fff0aa9e50a5199f
</pre>
 
=={{header|Swift}}==
Line 1,088 ⟶ 1,798:
 
{{works with|Swift|1.2+}}
<langsyntaxhighlight lang="swift">// Circular left shift: http://en.wikipedia.org/wiki/Circular_shift
// Precendence should be the same as <<
infix operator ~<< { precedence 160 associativity none }
Line 1,284 ⟶ 1,994:
}</langsyntaxhighlight>
 
Usage:
 
<langsyntaxhighlight lang="swift">var block = Block()
let message:[UInt32] = [ 0x65_73_6f_52, 0x20_61_74_74, 0x65_64_6f_43, 0x00_00_00_80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0 ]
block.compress(message)
let digest = NSString(format: "%2x%2x%2x%2x%2x", UInt32(bigEndian: block.hash[0]), UInt32(bigEndian: block.hash[1]),UInt32(bigEndian: block.hash[2]), UInt32(bigEndian: block.hash[3]), UInt32(bigEndian: block.hash[4]))
println(digest)</langsyntaxhighlight>
{{out}}
<pre>b3be159860842cebaa7174c8fff0aa9e50a5199f</pre>
Line 1,298 ⟶ 2,008:
=={{header|Tcl}}==
{{tcllib|ripemd160}}
<langsyntaxhighlight lang="tcl">package require ripemd160
 
puts [ripemd::ripemd160 -hex "Rosetta Code"]</langsyntaxhighlight>
{{out}}
<pre>b3be159860842cebaa7174c8fff0aa9e50a5199f</pre>
 
=={{header|Visual Basic}}==
{{works with|Visual Basic|6}}
{{works with|VBA|7}}
<syntaxhighlight lang="vb">'--- mdRipeMd160.bas
Option Explicit
DefObj A-Z
 
#Const HasPtrSafe = (VBA7 <> 0)
#Const HasOperators = (TWINBASIC <> 0)
 
#If HasPtrSafe Then
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
Private Declare PtrSafe Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As LongPtr, ByVal cchWideChar As Long, lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
#Else
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
#End If
 
Private Const LNG_BLOCKSZ As Long = 64
Private Const LNG_ROUNDS As Long = 80
Private Const LNG_HASHSZ As Long = 20
 
Public Type CryptoRipeMd160Context
H0 As Long
H1 As Long
H2 As Long
H3 As Long
H4 As Long
Partial(0 To LNG_BLOCKSZ - 1) As Byte
NPartial As Long
NInput As Currency
End Type
 
Private LNG_R0(0 To LNG_ROUNDS - 1) As Long
Private LNG_R1(0 To LNG_ROUNDS - 1) As Long
Private LNG_S0(0 To LNG_ROUNDS - 1) As Long
Private LNG_S1(0 To LNG_ROUNDS - 1) As Long
 
#If Not HasOperators Then
Private LNG_POW2(0 To 31) As Long
 
Private Function RotL32(ByVal lX As Long, ByVal lN As Long) As Long
'--- RotL32 = LShift(X, n) Or RShift(X, 32 - n)
Debug.Assert lN <> 0
RotL32 = ((lX And (LNG_POW2(31 - lN) - 1)) * LNG_POW2(lN) Or -((lX And LNG_POW2(31 - lN)) <> 0) * LNG_POW2(31)) Or _
((lX And (LNG_POW2(31) Xor -1)) \ LNG_POW2(32 - lN) Or -(lX < 0) * LNG_POW2(lN - 1))
End Function
 
Private Function UAdd32(ByVal lX As Long, ByVal lY As Long) As Long
If (lX Xor lY) >= 0 Then
UAdd32 = ((lX Xor &H80000000) + lY) Xor &H80000000
Else
UAdd32 = lX + lY
End If
End Function
#End If
 
Public Sub CryptoRipeMd160Init(uCtx As CryptoRipeMd160Context)
Dim vElem As Variant
Dim lIdx As Long
If LNG_R0(0) = 0 Then
For Each vElem In Split("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 7 4 13 1 10 6 15 3 12 0 9 5 2 14 11 8 3 10 14 4 9 15 8 1 2 7 0 6 13 11 5 12 1 9 11 10 0 8 12 4 13 3 7 15 14 5 6 2 4 0 5 9 7 12 2 10 14 1 3 8 11 6 15 13 5 14 7 0 9 2 11 4 13 6 15 8 1 10 3 12 6 11 3 7 0 13 5 10 14 15 8 12 4 9 1 2 15 5 1 3 7 14 6 9 11 8 12 2 10 0 4 13 8 6 4 1 3 11 15 0 5 12 2 13 9 7 10 14 12 15 10 4 1 5 8 7 6 2 13 14 0 3 9 11")
If lIdx < LNG_ROUNDS Then
LNG_R0(lIdx) = vElem
Else
LNG_R1(lIdx - LNG_ROUNDS) = vElem
End If
lIdx = lIdx + 1
Next
lIdx = 0
For Each vElem In Split("11 14 15 12 5 8 7 9 11 13 14 15 6 7 9 8 7 6 8 13 11 9 7 15 7 12 15 9 11 7 13 12 11 13 6 7 14 9 13 15 14 8 13 6 5 12 7 5 11 12 14 15 14 15 9 8 9 14 5 6 8 6 5 12 9 15 5 11 6 8 13 12 5 12 13 14 11 8 5 6 8 9 9 11 13 15 15 5 7 7 8 11 14 14 12 6 9 13 15 7 12 8 9 11 7 7 12 7 6 15 13 11 9 7 15 11 8 6 6 14 12 13 5 14 13 13 7 5 15 5 8 11 14 14 6 14 6 9 12 9 12 5 15 8 8 5 12 9 12 5 14 6 8 13 6 5 15 13 11 11")
If lIdx < LNG_ROUNDS Then
LNG_S0(lIdx) = vElem
Else
LNG_S1(lIdx - LNG_ROUNDS) = vElem
End If
lIdx = lIdx + 1
Next
#If Not HasOperators Then
LNG_POW2(0) = 1
For lIdx = 1 To 30
LNG_POW2(lIdx) = LNG_POW2(lIdx - 1) * 2
Next
LNG_POW2(31) = &H80000000
#End If
End If
With uCtx
.H0 = &H67452301: .H1 = &HEFCDAB89: .H2 = &H98BADCFE: .H3 = &H10325476: .H4 = &HC3D2E1F0
.NPartial = 0
.NInput = 0
End With
End Sub
 
#If HasOperators Then
[ IntegerOverflowChecks (False) ]
#End If
Public Sub CryptoRipeMd160Update(uCtx As CryptoRipeMd160Context, baInput() As Byte, Optional ByVal Pos As Long, Optional ByVal Size As Long = -1)
Static B(0 To 15) As Long
Dim lIdx As Long
Dim lA0 As Long
Dim lB0 As Long
Dim lC0 As Long
Dim lD0 As Long
Dim lE0 As Long
Dim lTemp0 As Long
Dim lK0 As Long
Dim lA1 As Long
Dim lB1 As Long
Dim lC1 As Long
Dim lD1 As Long
Dim lE1 As Long
Dim lTemp1 As Long
Dim lK1 As Long
With uCtx
If Size < 0 Then
Size = UBound(baInput) + 1 - Pos
End If
.NInput = .NInput + Size
If .NPartial > 0 Then
lIdx = LNG_BLOCKSZ - .NPartial
If lIdx > Size Then
lIdx = Size
End If
Call CopyMemory(.Partial(.NPartial), baInput(Pos), lIdx)
.NPartial = .NPartial + lIdx
Pos = Pos + lIdx
Size = Size - lIdx
End If
Do While Size > 0 Or .NPartial = LNG_BLOCKSZ
If .NPartial <> 0 Then
Call CopyMemory(B(0), .Partial(0), LNG_BLOCKSZ)
.NPartial = 0
ElseIf Size >= LNG_BLOCKSZ Then
Call CopyMemory(B(0), baInput(Pos), LNG_BLOCKSZ)
Pos = Pos + LNG_BLOCKSZ
Size = Size - LNG_BLOCKSZ
Else
Call CopyMemory(.Partial(0), baInput(Pos), Size)
.NPartial = Size
Exit Do
End If
'--- RipeMd160 step
lA0 = .H0: lB0 = .H1: lC0 = .H2: lD0 = .H3: lE0 = .H4
lA1 = .H0: lB1 = .H1: lC1 = .H2: lD1 = .H3: lE1 = .H4
For lIdx = 0 To LNG_ROUNDS - 1
Select Case lIdx \ 16
Case 0
lTemp0 = lB0 Xor lC0 Xor lD0
lTemp1 = lB1 Xor (lC1 Or Not lD1)
lK0 = 0: lK1 = &H50A28BE6
Case 1
lTemp0 = (lB0 And lC0) Or (Not lB0 And lD0)
lTemp1 = (lB1 And lD1) Or (lC1 And Not lD1)
lK0 = &H5A827999: lK1 = &H5C4DD124
Case 2
lTemp0 = (lB0 Or Not lC0) Xor lD0
lTemp1 = (lB1 Or Not lC1) Xor lD1
lK0 = &H6ED9EBA1: lK1 = &H6D703EF3
Case 3
lTemp0 = (lB0 And lD0) Or (lC0 And Not lD0)
lTemp1 = (lB1 And lC1) Or (Not lB1 And lD1)
lK0 = &H8F1BBCDC: lK1 = &H7A6D76E9
Case 4
lTemp0 = lB0 Xor (lC0 Or Not lD0)
lTemp1 = lB1 Xor lC1 Xor lD1
lK0 = &HA953FD4E: lK1 = 0
End Select
#If HasOperators Then
lTemp0 += lA0 + B(LNG_R0(lIdx)) + lK0
lTemp0 = (lTemp0 << LNG_S0(lIdx) Or lTemp0 >> (32 - LNG_S0(lIdx))) + lE0
lTemp1 += lA1 + B(LNG_R1(lIdx)) + lK1
lTemp1 = (lTemp1 << LNG_S1(lIdx) Or lTemp1 >> (32 - LNG_S1(lIdx))) + lE1
#Else
lTemp0 = UAdd32(RotL32(UAdd32(UAdd32(UAdd32(lTemp0, lA0), B(LNG_R0(lIdx))), lK0), LNG_S0(lIdx)), lE0)
lTemp1 = UAdd32(RotL32(UAdd32(UAdd32(UAdd32(lTemp1, lA1), B(LNG_R1(lIdx))), lK1), LNG_S1(lIdx)), lE1)
#End If
lA0 = lE0: lA1 = lE1
lE0 = lD0: lE1 = lD1
#If HasOperators Then
lD0 = (lC0 << 10 Or lC0 >> 22): lD1 = (lC1 << 10 Or lC1 >> 22)
#Else
lD0 = RotL32(lC0, 10): lD1 = RotL32(lC1, 10)
#End If
lC0 = lB0: lC1 = lB1
lB0 = lTemp0: lB1 = lTemp1
Next
#If HasOperators Then
lTemp0 = .H1 + lC0 + lD1
.H1 = .H2 + lD0 + lE1
.H2 = .H3 + lE0 + lA1
.H3 = .H4 + lA0 + lB1
.H4 = .H0 + lB0 + lC1
.H0 = lTemp0
#Else
lTemp0 = UAdd32(UAdd32(.H1, lC0), lD1)
.H1 = UAdd32(UAdd32(.H2, lD0), lE1)
.H2 = UAdd32(UAdd32(.H3, lE0), lA1)
.H3 = UAdd32(UAdd32(.H4, lA0), lB1)
.H4 = UAdd32(UAdd32(.H0, lB0), lC1)
.H0 = lTemp0
#End If
Loop
End With
End Sub
 
Public Sub CryptoRipeMd160Finalize(uCtx As CryptoRipeMd160Context, baOutput() As Byte)
Static B(0 To 4) As Long
Dim P(0 To LNG_BLOCKSZ + 9) As Byte
Dim lSize As Long
With uCtx
lSize = LNG_BLOCKSZ - .NPartial
If lSize < 9 Then
lSize = lSize + LNG_BLOCKSZ
End If
P(0) = &H80
.NInput = .NInput / 10000@ * 8
Call CopyMemory(P(lSize - 8), .NInput, 8)
CryptoRipeMd160Update uCtx, P, Size:=lSize
Debug.Assert .NPartial = 0
B(0) = .H0: B(1) = .H1: B(2) = .H2: B(3) = .H3: B(4) = .H4
ReDim baOutput(0 To LNG_HASHSZ - 1) As Byte
Call CopyMemory(baOutput(0), B(0), UBound(baOutput) + 1)
End With
End Sub
 
Public Function CryptoRipeMd160ByteArray(baInput() As Byte, Optional ByVal Pos As Long, Optional ByVal Size As Long = -1) As Byte()
Dim uCtx As CryptoRipeMd160Context
CryptoRipeMd160Init uCtx
CryptoRipeMd160Update uCtx, baInput, Pos, Size
CryptoRipeMd160Finalize uCtx, CryptoRipeMd160ByteArray
End Function
 
Private Function ToUtf8Array(sText As String) As Byte()
Const CP_UTF8 As Long = 65001
Dim baRetVal() As Byte
Dim lSize As Long
lSize = WideCharToMultiByte(CP_UTF8, 0, StrPtr(sText), Len(sText), ByVal 0, 0, 0, 0)
If lSize > 0 Then
ReDim baRetVal(0 To lSize - 1) As Byte
Call WideCharToMultiByte(CP_UTF8, 0, StrPtr(sText), Len(sText), baRetVal(0), lSize, 0, 0)
Else
baRetVal = vbNullString
End If
ToUtf8Array = baRetVal
End Function
 
Private Function ToHex(baData() As Byte) As String
Dim lIdx As Long
Dim sByte As String
ToHex = String$(UBound(baData) * 2 + 2, 48)
For lIdx = 0 To UBound(baData)
sByte = LCase$(Hex$(baData(lIdx)))
If Len(sByte) = 1 Then
Mid$(ToHex, lIdx * 2 + 2, 1) = sByte
Else
Mid$(ToHex, lIdx * 2 + 1, 2) = sByte
End If
Next
End Function
 
Public Function CryptoRipeMd160Text(sText As String) As String
CryptoRipeMd160Text = ToHex(CryptoRipeMd160ByteArray(ToUtf8Array(sText)))
End Function
</syntaxhighlight>
<syntaxhighlight lang="vb">Debug.Print CryptoRipeMd160Text("Rosetta code")</syntaxhighlight>
{{out}}
<pre>1cda558e41e47c3090aafd73ca5651d176f95ca9</pre>
 
=={{header|Wren}}==
{{libheader|Wren-crypto}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="wren">import "./crypto" for Ripemd160
import "./fmt" for Fmt
var strings = [
"",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
"The quick brown fox jumps over the lazy dog",
"The quick brown fox jumps over the lazy cog",
"Rosetta Code"
]
for (s in strings) {
var hash = Ripemd160.digest(s)
Fmt.print("$s <== '$0s'", hash, s)
}</syntaxhighlight>
 
{{out}}
<pre>
9c1185a5c5e9fc54612808977ee8f548b2258d31 <== ''
0bdc9d2d256b3ee9daae347be6f4dc835a467ffe <== 'a'
8eb208f7e05d987a9b044a8e98c6b087f15a0bfc <== 'abc'
5d0689ef49d2fae572b881b123a85ffa21595f36 <== 'message digest'
f71c27109c692c1b56bbdceb5b9d2865b3708dbc <== 'abcdefghijklmnopqrstuvwxyz'
b0e20b6e3116640286ed3a87a5713079b21f5189 <== 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
9b752e45573d4b39f4dbd3323cab82bf63326bfb <== '12345678901234567890123456789012345678901234567890123456789012345678901234567890'
37f332f68db77bd9d7edd4969571ad671cf9dd3b <== 'The quick brown fox jumps over the lazy dog'
132072df690933835eb8b6ad0b77e7b6f14acad7 <== 'The quick brown fox jumps over the lazy cog'
b3be159860842cebaa7174c8fff0aa9e50a5199f <== 'Rosetta Code'
</pre>
 
=={{header|zkl}}==
Uses shared library zklMsgHash.so
<langsyntaxhighlight lang="zkl">var MsgHash=Import("zklMsgHash");
MsgHash.RIPEMD160("Rosetta Code")</langsyntaxhighlight>
{{out}}
<pre>b3be159860842cebaa7174c8fff0aa9e50a5199f</pre>
9,476

edits