MD5: Difference between revisions
m
syntax highlighting fixup automation
(add task to arm assembly raspberry pi) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 15:
=={{header|8th}}==
<
"md5" cr:hash! "Some text" cr:hash cr:hash>s
. cr bye
</syntaxhighlight>
{{out}}
<tt>
Line 26:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program MD5_64.s */
Line 406:
.include "../includeARM64.inc"
</syntaxhighlight>
<pre>
Result for => D41D8CD98F00B204E9800998ECF8427E
Line 417:
=={{header|Ada}}==
{{works with|GNAT}}
<
with GNAT.MD5;
Line 423:
begin
Put(GNAT.MD5.Digest("Foo bar baz"));
end MD5_Digest;</
=={{header|ALGOL 68}}==
<
# Based on wikipedia article pseudocode #
Line 578:
print (("failed"))
FI
</syntaxhighlight>
=={{header|APL}}==
{{works with|Dyalog APL}}
<
md5←{
⍝ index origin zero
Line 623:
(⎕D,⎕A)[,⍉(2⍴16)⊤,⍉⊖(4⍴256)⊤M loop A B C D]
}
</syntaxhighlight>
=={{header|Arturo}}==
<
{{out}}
Line 634:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program MD5.s */
Line 1,017:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
<pre>
Result for abc => 900150983CD24FB0D6963F7D28E17F72
Line 1,029:
===Regular version===
Source: [http://www.autohotkey.com/forum/post-275910.html#275910 AutoHotkey forum] by SKAN
<
MsgBox % MD5(data,StrLen(data)) ; 900150983cd24fb0d6963f7d28e17f72
Line 1,040:
Return MD5
}
</syntaxhighlight>
===Native implementation===
Source: [http://www.autohotkey.com/forum/topic17853.html AutoHotkey forum] by Laszlo
<
r = 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22
, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20
Line 1,118:
SetFormat Integer, DECIMAL
Return x
}</
=={{header|BaCon}}==
<
PRAGMA INCLUDE <stdio.h>
PRAGMA INCLUDE <stdlib.h>
Line 1,138:
FOR i = 0 TO MD5_DIGEST_LENGTH-1
PRINT result[i] FORMAT "%02x"
NEXT</
=={{header|BASIC256}}==
<
print MD5("a")
print MD5("abc")
Line 1,149:
print MD5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
print MD5("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
end</
{{out}}
<pre>d41d8cd98f00b204e9800998ecf8427e
Line 1,163:
{{works with|BBC BASIC for Windows}}
See [[MD5/Implementation]] for a native version.
<
PRINT FN_MD5("a")
PRINT FN_MD5("abc")
Line 1,181:
MD5$ += RIGHT$("0"+STR$~(MD5_CTX.digest&(I%)),2)
NEXT
= MD5$</
=={{header|C}}==
{{libheader|OpenSSL}}
<
#include <stdlib.h>
#include <string.h>
Line 1,205:
return EXIT_SUCCESS;
}</
Implementation of md5
(Needs review - differences observed for the last 8 characters when compared with openssl implementation)
<
#include <stdio.h>
#include <string.h>
Line 1,349:
return 0;
}</
=={{header|C sharp|C#}}==
<
using System.Security.Cryptography;
byte[] data = Encoding.ASCII.GetBytes("The quick brown fox jumped over the lazy dog's back");
byte[] hash = MD5.Create().ComputeHash(data);
Console.WriteLine(BitConverter.ToString(hash).Replace("-", "").ToLower());</
=={{header|C++}}==
{{libheader|Poco Crypto}}
<
#include <iostream>
#include "Poco/MD5Engine.h"
Line 1,380:
<< " !" << std::endl ;
return 0 ;
}</
{{out}}
<pre>The quick brown fox jumped over the lazy dog's back as a MD5 digest :
Line 1,393:
=={{header|Clojure}}==
<
(map (partial format "%02x")
(.digest (doto (java.security.MessageDigest/getInstance "MD5")
.reset
(.update (.getBytes "The quick brown fox jumps over the lazy dog"))))))</
=={{header|COBOL}}==
<syntaxhighlight lang="cobol">
IDENTIFICATION DIVISION.
PROGRAM-ID. MD5.
Line 1,463:
CLOSE Tmp-MD5.
CALL "CBL_DELETE_FILE" USING '/tmp/MD5'.
</syntaxhighlight>
<syntaxhighlight lang="cobol">
IDENTIFICATION DIVISION.
Line 1,553:
END FUNCTION MD5.
</syntaxhighlight>
{{Out}}
<pre>
Line 1,562:
=={{header|Common Lisp}}==
{{libheader|Ironclad}}
<
(defun md5 (str)
(ironclad:byte-array-to-hex-string
Line 1,576:
(dolist (msg *tests*)
(format T "~s: ~a~%" msg (md5 msg)))
</syntaxhighlight>
{{Out}}
Line 1,588:
<h5>Another method using openssl:</h5> {{libheader|CFFI}}
<
(cffi:defcfun ("MD5" MD5) :void (string :string) (len :int) (ptr :pointer))
Line 1,597:
(loop for i from 0 below 16 do
(format t "~a" (write-to-string (cffi:mem-ref ptr :unsigned-char i) :base 16)))
(cffi:foreign-free ptr))</
{{Out}}<pre>E38CA1D920C4B8B8D3946B2C72F01680</pre>
=={{header|Crystal}}==
<
puts Digest::MD5.hexdigest("The quick brown fox jumped over the lazy dog's back")</
{{Out}}<pre>e38ca1d920c4b8b8d3946b2c72f01680</pre>
=={{header|D}}==
<
import std.stdio, std.digest.md;
auto txt = "The quick brown fox jumped over the lazy dog's back";
writefln("%-(%02x%)", txt.md5Of);
}</
{{out}}
<pre>e38ca1d920c4b8b8d3946b2c72f01680</pre>
Alternative version:
{{libheader|Tango}}
<
void main(char[][] args) {
Line 1,626:
Stdout.formatln("[{}]=>\n[{}]", args[i], md5.hexDigest());
}
}</
Output:
<pre>>md5test "The quick brown fox jumped over the lazy dog's back"
Line 1,634:
=={{header|Delphi}}==
If you require a native implementation, look inside the class '''TIdHashMessageDigest5'''. This class is placed in the unit '''IdHashMessageDigest.pas'''.
<
{$APPTYPE CONSOLE}
Line 1,660:
Writeln(MD5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'));
Readln;
end.</
'''Output:'''
<pre>
Line 1,675:
{{works with|E-on-Java}}
{{trans|Java}} (with modifications)
<
def sprintf := <import:java.lang.makeString>.format
Line 1,684:
print(sprintf("%02x", [b]))
}
println()</
=={{header|Emacs Lisp}}==
<
(secure-hash 'md5 "The quick brown fox jumped over the lazy dog's back") ;=> "e38ca1d920c4b8b8d3946b2c72f01680"</
=={{header|Erlang}}==
By default, Erlang's crypto functions like md5 return a binary value rather than a hex string. We have two write our own function to translate it:
<
-export([md5/1]).
Line 1,699:
string:to_upper(
lists:flatten([io_lib:format("~2.16.0b",[N]) || <<N>> <= erlang:md5(S)])
).</
Testing it:
<
{ok,tests}
2> tests:md5("The quick brown fox jumped over the lazy dog's back").
"E38CA1D920C4B8B8D3946B2C72F01680"</
=={{header|F_Sharp|F#}}==
Using built-in System.Security.Cryptography.MD5 class (Link to original blog [https://znprojects.blogspot.com/2017/04/md5-in-f-functionally.html]).
<
use md5 = System.Security.Cryptography.MD5.Create()
msg
Line 1,717:
|> Seq.reduce ( + )
md5ootb @"The quick brown fox jumped over the lazy dog's back"</
=={{header|Factor}}==
Line 1,728:
=={{header|Forth}}==
{{libheader|Forth Foundation Library}}
<
\ Create a MD5 variable md1 in the dictionary
Line 1,745:
\ Convert the hash value to a hex string and print it
md5+to-string type cr</
=={{header|Fortran}}==
Line 1,751:
Using Windows API. See [https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptacquirecontexta CryptAcquireContextA], [https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptcreatehash CryptCreateHash], [https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-crypthashdata CryptHashData] and [https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptgethashparam CryptGetHashParam] in Microsoft documentation.
<
use kernel32
use advapi32
Line 1,844:
deallocate(name)
end do
end program</
=={{header|FreeBASIC}}==
Line 1,851:
=={{header|Frink}}==
The function <CODE>messageDigest[string, hash]</CODE> returns a hex-encoded hash of any input string with a variety of hashing functions.
<
=={{header|Futhark}}==
Line 1,857:
Real languages roll their own crypto.
<syntaxhighlight lang="futhark">
type md5 = (u32, u32, u32, u32)
Line 1,933:
in (d, b + rotate_left(a + f + (ks())[i] + m[g], (rs())[i]), b, c)
in (a,b,c,d)
</syntaxhighlight>
=={{header|Go}}==
<
import (
Line 1,975:
fmt.Println(" got: ", sum)
}
}</
=={{header|Groovy}}==
<
String.metaClass.md5Checksum = {
MessageDigest.getInstance('md5').digest(delegate.bytes).collect { String.format("%02x", it) }.join('')
}</
Testing
<
=={{header|Haskell}}==
Use modules nano-MD5 and ByteString from [http://hackage.haskell.org/packages/hackage.html HackageDB]
<
import Data.ByteString (pack)
import Data.Char (ord)
Line 1,995:
let message = "The quick brown fox jumped over the lazy dog's back"
digest = (md5sum . pack . map (fromIntegral . ord)) message
putStrLn digest</
Use in GHCi:
Line 2,003:
This version uses the [https://hackage.haskell.org/package/cryptonite Cryptonite] package:
{{libheader|Cryptonite}}
<
import Data.ByteString.Char8 (pack)
Line 2,011:
main :: IO ()
main = print . md5 . pack . unwords =<< getArgs
where md5 x = hash x :: Digest MD5</
{{out}}
<pre>
Line 2,019:
=={{header|Haxe}}==
<
class Main {
Line 2,026:
Sys.println(md5);
}
}</
{{out}}
Line 2,033:
=={{header|Icon}} and {{header|Unicon}}==
The following program demonstrates the MD5 using a native Icon/Unicon implementation (see [[MD5/Implementation]]) and checks the results against reference values. Alternate implementations using call outs to md5sum on Linux or fciv on windows are possible but were not coded.
<
testMD5("The quick brown fox jumps over the lazy dog", 16r9e107d9d372bb6826bd81d3542a419d6)
testMD5("The quick brown fox jumps over the lazy dog.", 16re4d909c290d0fb1ca068ffaddf22cbd0)
Line 2,042:
write("Message(length=",*s,") = ",image(s))
write("Digest = ",hexstring(h := MD5(s)),if h = rh then " matches reference hash" else (" does not match reference hash = " || hexstring(rh)),"\n")
end</
Sample Output:<pre>Message(length=43) = "The quick brown fox jumps over the lazy dog"
Line 2,054:
=={{header|Io}}==
<
==> MD5_0x97663e0:
appendSeq = MD5_appendSeq()
Line 2,060:
md5String = MD5_md5String()
Io> MD5 clone appendSeq("The quick brown fox jumped over the lazy dog's back") md5String
==> e38ca1d920c4b8b8d3946b2c72f01680</
=={{header|J}}==
Using the <tt>[https://github.com/jsoftware/convert_misc/blob/master/md5.ijs md5]</tt> script from the <tt>convert/misc</tt> addon package:
<
md5 'The quick brown fox jumped over the lazy dog''s back'
e38ca1d920c4b8b8d3946b2c72f01680</
Implementation here, in case the link to the script goes dead again:
<
'`lt gt ge xor'=: (20 b.)`(18 b.)`(27 b.)`(22 b.)
Line 2,148:
end.
hexlist r
}}</
An alternative and faster approach is to use the Qt library function available using the <tt>ide/qt</tt> addon from J8:
<
getmd5=: 'md5'&gethash_jqtide_
getmd5 'The quick brown fox jumped over the lazy dog''s back'
e38ca1d920c4b8b8d3946b2c72f01680</
=={{header|Java}}==
<
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Line 2,181:
}
}
}</
Other options for digest algorithms (to replace "MD5" in the example above) include: MD2, SHA-1, SHA-256, SHA-384, and SHA-512.
Line 2,187:
=={{header|Jsish}}==
<
var str = 'Rosetta code';
puts(Util.hash(str, {type:'md5'}));
Line 2,213:
MD5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') ==> 57edf4a22be3c955ac49da2e2107b67a
=!EXPECTEND!=
*/</
{{out}}
Line 2,235:
{{works with|Julia|0.6}}
<
function Base.trunc(s::AbstractString, n::Integer)
Line 2,266:
println("* The sum should be ", h)
end
end</
{{out}}
Line 2,280:
=={{header|Kotlin}}==
<
import java.security.MessageDigest
Line 2,291:
for (byte in digest) print("%02x".format(byte))
println()
}</
{{out}}
Line 2,299:
=={{header|Lasso}}==
<
//80ba88ee2600e9e9b36e739458c39ebd</
===Test suite===
<
'a' = '0cc175b9c0f1b6a831c399e269772661',
'abc' = '900150983cd24fb0d6963f7d28e17f72',
Line 2,314:
with a in #test->keys do => {^
'testing: "'+#a+'": '+(Encrypt_MD5(#a)->asBytes == #test->find(#a)->asBytes)+'\r'
^}</
{{out}}
<pre>testing: "12345678901234567890123456789012345678901234567890123456789012345678901234567890": true
Line 2,324:
=={{header|Liberty BASIC}}==
<
'from tsh73's January 2008 code
Line 2,468:
a$=left$("00000000", 8-len(a$))+a$
revOrd$ = lower$(mid$(a$,7,2)+mid$(a$,5,2)+mid$(a$,3,2)+mid$(a$,1,2))
end function</
=={{header|Lingo}}==
Line 2,474:
*Using a binary plugin ("Xtra"):
{{libheader|Crypto Xtra}}
<syntaxhighlight lang
*Pure Lingo implementation
<
-- Calculates MD5 hash of string or bytearray
-- @param {bytearray|string} input
Line 2,752:
ba.position = 1
return ba
end</
=={{header|LiveCode}}==
Livecode has built-in support for md4 and md5
<
local md5, mdhex
put md5Digest(hashtext) into md5
get binaryDecode("H*",md5,mdhex)
return mdhex
end md5sum</
Tests<
// rfc1321 MD5 test suite:
local md5
Line 2,786:
end repeat
put results
end md5testsuite</
Output
<pre>ok abc
Line 2,798:
=={{header|Lua}}==
Using the [http://www.keplerproject.org/md5/ Kepler MD5 library]:
<
--printing a sum:
Line 2,813:
test("abcdefghijklmnopqrstuvwxyz","c3fcd3d76192e4007dfb496cca67e13b")
test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789","d174ab98d277d9f5a5611c2c9f419d9f")
test("12345678901234567890123456789012345678901234567890123456789012345678901234567890","57edf4a22be3c955ac49da2e2107b67a")</
=={{header|Maple}}==
The <tt>Hash</tt> command in the <tt>StringTools</tt> package computes the MD5 hash value of a string.
<syntaxhighlight lang="maple">
> with( StringTools ):
> Hash( "" );
Line 2,839:
> Hash( "12345678901234567890123456789012345678901234567890123456789012345678901234567890" );
"57edf4a22be3c955ac49da2e2107b67a"
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Mathematica has built-in functions Hash and FileHash.
Example:
<
gives back:
<syntaxhighlight lang
=={{header|MATLAB}}==
This code also works with Octave (but Octave already provides md5sum(), see [[{{FULLPAGENAME}}#Octave|Octave example]]).
<
% digest = md5(message)
% Compute the MD5 digest of the message, as a hexadecimal digest.
Line 2,966:
digest = dec2hex(digest);
digest = reshape(transpose(digest), 1, numel(digest));
end %md5</
Sample Usage:
<
ans = CCA1BF66B09554E10F837838C3D3EFB1</
=={{header|min}}==
{{works with|min|0.19.6}}
<
=={{header|MOO}}==
<
player:tell(string_hash(string));</
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
MD5 in Neko
Tectonics:
Line 2,994:
/* Output in lowercase hex */
$print(base_encode(result, "0123456789abcdef"));</
{{out}}
Line 3,003:
=={{header|Nemerle}}==
{{trans|C#}}
<
using System.Console;
using System.Text;
Line 3,036:
Write($"$(IsValidMD5(test.Key, test.Value)) ");
}
}</
Output:
<pre>True True True True True True True True</pre>
=={{header|NetRexx}}==
<
options replace format comments java crossref savelog symbols binary
Line 3,100:
return digestSum
</syntaxhighlight>
'''Output:'''
<pre>
Line 3,138:
=={{header|NewLISP}}==
<
;; (import native functions from the crypto library, provided by OpenSSL)
(module "crypto.lsp")
(crypto:md5 "The quick brown fox jumped over the lazy dog's back")</
=={{header|Nim}}==
<
echo toMD5("The quick brown fox jumped over the lazy dog's back")</
{{out}}
Line 3,153:
=={{header|Oberon-2}}==
{{works with|oo2c}}{{libheader|crypto}}
<
MODULE MD5;
IMPORT
Line 3,171:
Out.String("MD5: ");Utils.PrintHex(str,0,h.size);Out.Ln
END MD5.
</syntaxhighlight>
{{out}}
<pre>
Line 3,179:
=={{header|Objeck}}==
<
class MD5 {
function : Main(args : String[]) ~ Nil {
Line 3,187:
}
}
</syntaxhighlight>
=={{header|Objective-C}}==
{{works with|GNUstep}} only; not Cocoa
<
NSData *digest = [[myString dataUsingEncoding:NSUTF8StringEncoding] md5Digest]; // or another encoding of your choosing
NSLog(@"%@", [digest hexadecimalRepresentation]);</
{{works with|iPhone}}
{{works with|Mac OS X}}
<
NSString *myString = @"The quick brown fox jumped over the lazy dog's back";
Line 3,208:
}
NSLog(@"%@", hex);
}</
{{works with|Mac OS X}} (need to include "libcrypto.dylib" framework)
<
NSString *myString = @"The quick brown fox jumped over the lazy dog's back";
Line 3,222:
}
NSLog(@"%@", hex);
}</
=={{header|OCaml}}==
<
- : string = "e38ca1d920c4b8b8d3946b2c72f01680"</
=={{header|Octave}}==
<
hash = md5sum(s, true);
disp(hash)</
For an implementation of MD5, see [[{{FULLPAGENAME}}#MATLAB|MATLAB example]].
=={{header|Ol}}==
<
(import (otus ffi))
(define libcrypto (load-dynamic-library "libcrypto.so.1.0.0"))
(define MD5 (libcrypto type-vptr "MD5" type-string fft-unsigned-long type-string))
</syntaxhighlight>
{{Out}}
<
(define (test str)
(define md5 "----------------")
Line 3,260:
(test "abcdefghijklmnopqrstuvwxyz")
(test "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
(test "12345678901234567890123456789012345678901234567890123456789012345678901234567890")</
<pre>
Line 3,274:
=={{header|OpenEdge/Progress}}==
The MD5-DIGEST function is readily available, the output is passed thru HEX-ENCODE to convert the raw result to a hexadecimal string, this then needs to be passed thru STRING for display purposes.
<
1 STRING( HEX-ENCODE( MD5-DIGEST( "" ) ) ) SKIP
2 STRING( HEX-ENCODE( MD5-DIGEST( "a" ) ) ) SKIP
Line 3,282:
6 STRING( HEX-ENCODE( MD5-DIGEST( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ) ) ) SKIP
7 STRING( HEX-ENCODE( MD5-DIGEST( "12345678901234567890123456789012345678901234567890123456789012345678901234567890" ) ) )
VIEW-AS ALERT-BOX</
Output:
Line 3,304:
Build a MD5 plugin using Linux system library and PARI's function interface. (Linux solution)
<
#include <openssl/md5.h>
Line 3,330:
return strtoGENstr(hash);
}</
Compile with: gcc -Wall -O2 -fPIC -shared md5.c -o libmd5.so -lcrypt -lpari
Load plugin from your home directory into PARI:
<
MD5("The quick brown fox jumped over the lazy dog's back") </
Output:
Line 3,343:
Here is an explicit implementation in the PARI/GP language:
<
a = 0x67452301, b = 0xefcdab89, c = 0x98badcfe, d = 0x10325476,
s = [ 7, 12, 17, 22; 5, 9, 14, 20; 4, 11, 16, 23; 6, 10, 15, 21 ],
Line 3,365:
); \\ end forstep
Strprintf("%032x",fromdigits(Vecrev(digits(fromdigits([d,c,b,a],2^32),256),16),256))
}</
Then:
<
<pre>
%2 = "d41d8cd98f00b204e9800998ecf8427e"
</pre>
<
<pre>
%3 = "4c57070257998981a0c7b7ec003b9d5c"
Line 3,378:
==Pascal==
Pascal has a built-in unit called md5. It can be used to get a digest both for a string and a file.
<syntaxhighlight lang="pascal">
program GetMd5;
Line 3,390:
writeln(strEncrypted);
end.
</syntaxhighlight>
{{out}}
Line 3,400:
=={{header|Perl}}==
{{libheader|Digest::MD5}}
<
print md5_hex("The quick brown fox jumped over the lazy dog's back"), "\n";</
The same in OO manner
<
$md5 = Digest::MD5->new;
$md5->add("The quick brown fox jumped over the lazy dog's back");
print $md5->hexdigest, "\n";</
=={{header|Phix}}==
Line 3,416:
=={{header|PHP}}==
<
echo md5( $string );</
=={{header|PicoLisp}}==
Using the openssl library (the 'native' function is only in the 64-bit
version available):
<
(pack
(mapcar '((B) (pad 2 (hex B)))
(native "libcrypto.so" "MD5" '(B . 16) Str (length Str) '(NIL (16))) ) ) )</
Output:
<pre>-> "E38CA1D920C4B8B8D3946B2C72F01680"</pre>
=={{header|Pike}}==
<
import Crypto.MD5;
int main(){
write( string2hex( hash( "The quick brown fox jumped over the lazy dog's back" ) ) + "\n" );
}</
=={{header|PowerShell}}==
{{trans|C#}}
<
$data = [Text.Encoding]::UTF8.GetBytes($string)
$hash = [Security.Cryptography.MD5]::Create().ComputeHash($data)
([BitConverter]::ToString($hash) -replace '-').ToLower()</
=={{header|PureBasic}}==
;Purebasic 5.x versions:
<
test$ = "The quick brown fox jumped over the lazy dog's back"
Line 3,452:
; Call StringFingerprint() function and display MD5 result in Debug window
Debug StringFingerprint(test$, #PB_Cipher_MD5)
</syntaxhighlight>
=={{header|Python}}==
Line 3,458:
;Python 3.x, 2.5 and later 2.x versions:
<
>>> # RFC 1321 test suite:
>>> tests = (
Line 3,470:
>>> for text, golden in tests: assert hashlib.md5(text).hexdigest() == golden
>>> </
;Python 2.5 and later:
<
>>> print hashlib.md5("The quick brown fox jumped over the lazy dog's back").hexdigest()
e38ca1d920c4b8b8d3946b2c72f01680</
;Pre-2.5; removed in 3.x:
<
>>> print md5.md5("The quick brown fox jumped over the lazy dog's back").hexdigest()
e38ca1d920c4b8b8d3946b2c72f01680</
=={{header|R}}==
<
hexdigest <- digest("The quick brown fox jumped over the lazy dog's back",
algo="md5", serialize=FALSE)</
=={{header|Racket}}==
<
#lang racket
(require file/md5)
Line 3,499:
(md5 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
(md5 "12345678901234567890123456789012345678901234567890123456789012345678901234567890")
</syntaxhighlight>
Output:
Line 3,516:
(formerly Perl 6)
Library [http://github.com/cosimo/perl6-digest-md5/ Digest::MD5]
<syntaxhighlight lang="raku"
say Digest::MD5.md5_hex: "The quick brown fox jumped over the lazy dog's back";</
=={{header|REBOL}}==
<
== #{08A008A01D498C404B0C30852B39D3B8}</
=={{header|REXX}}==
<
msg.1 = /*─────MD5 test suite [from above doc].*/
msg.2 = 'a'
Line 3,637:
return .a(.Lr(right(d2c(_+c2d(w) +c2d(.h(x,y,z))+c2d(!.n)),4,'0'x),m),x)
.part4: procedure expose !.; parse arg w,x,y,z,n,m,_; n=n+1
return .a(.Lr(right(d2c(c2d(w) +c2d(.i(x,y,z))+c2d(!.n)+_),4,'0'x),m),x)</
'''output''' when using the default (internal) inputs:
<pre>
Line 3,663:
=={{header|Ring}}==
<
See MD5("my string!") + nl
# output : a83a049fbe50cf7334caa86bf16a3520
</syntaxhighlight>
=={{header|RLaB}}==
Line 3,675:
calculated in RLaB is the same as the hash of the same string vector written to a file.
<
The quick brown fox jumped over the lazy dog's back
>> hash("md5", x)
e38ca1d920c4b8b8d3946b2c72f01680</
=={{header|RPG}}==
Modified from [http://www.mysamplecode.com/2011/05/rpgle-generate-sha-1-hash-use.html]:
<
Ctl-opt MAIN(Main);
Ctl-opt DFTACTGRP(*NO) ACTGRP(*NEW);
Line 3,771:
endfor;
return;
end-proc;</
Note that this implementation converts the input from EBCDIC to ASCII before computing the hash.
Line 3,782:
=={{header|Ruby}}==
<
Digest::MD5.hexdigest("The quick brown fox jumped over the lazy dog's back")
# => "e38ca1d920c4b8b8d3946b2c72f01680"</
=={{header|Rust}}==
Cargo.toml
<
[dependencies]
rust-crypto = "0.2"
</syntaxhighlight>
src/main.rs
<
extern crate crypto;
Line 3,805:
println!("{}", sh.result_str());
}
</syntaxhighlight>
=={{header|S-lang}}==
Support for MD5 and SHA-1 are included in the standard "chksum" library:
<
print(md5sum("The quick brown fox jumped over the lazy dog's back"));</
{{out}}
Line 3,817:
=={{header|Scala}}==
<
def MD5(s: String): String = {
Line 3,837:
import scala.compat.Platform.currentTime
println(s"Successfully completed without errors. [total ${currentTime - executionStart} ms]")
}</
=={{header|Seed7}}==
<
include "msgdigest.s7i";
Line 3,846:
begin
writeln(hex(md5("The quick brown fox jumped over the lazy dog's back")));
end func;</
{{out}}
Line 3,855:
=={{header|Sidef}}==
{{libheader|Digest::MD5}}
<
say digest.md5_hex("The quick brown fox jumped over the lazy dog's back");</
The same in OO manner
<
md5.add("The quick brown fox jumped over the lazy dog's back");
say md5.hexdigest;</
=={{header|Slate}}==
You must load the code in 'src/lib/md5.slate'.
<
=={{header|Smalltalk}}==
Line 3,871:
{{works with|GNU Smalltalk}}
<
(MD5 hexDigestOf: 'The quick brown fox jumped over the lazy dog''s back') displayNl.</
{{works with|Smalltalk/X}}
<
=={{header|SQL}}==
{{works with|MySQL}}
<
=={{header|Suneido}}==
<
=={{header|Tcl}}==
{{tcllib|md5}}
<
puts [md5::md5 -hex "The quick brown fox jumped over the lazy dog's back"]
# ==> E38CA1D920C4B8B8D3946B2C72F01680</
=={{header|UNIX Shell}}==
Line 3,894:
[[GNU]] coreutils has ''md5sum'':
<
Several [[BSD]] systems have ''md5:''
<
{{libheader|OpenSSL}}
<
openssl md5 | sed 's/.*= //'</
=={{header|Visual Basic .NET}}==
{{works with|Visual Basic .NET|9.0+}}
<
Imports System.Text
Line 3,930:
End Module
</syntaxhighlight>
{{out}}
Line 3,938:
=={{header|Vlang}}==
<
fn main() {
Line 3,970:
println('MD5 succeeded $s')
}
}</
{{out}}
<pre>MD5 succeeded
Line 3,986:
{{libheader|Wren-fmt}}
This script uses a library implementation of MD5 (based on the implementation in the [[MD5/Implementation#Wren]] task) to process the Wikipedia examples.
<
import "/fmt" for Fmt
Line 3,998:
var digest = Md5.digest(s)
Fmt.print("$s <== '$0s'", digest, s)
}</
{{out}}
Line 4,009:
=={{header|zkl}}==
md5 is a built in utility
<
Utils.MD5.calc("abcdefghijklmnopqrstuvwxyz"); //-->"c3fcd3d76192e4007dfb496cca67e13b"</
|