Jump to content

MD5: Difference between revisions

47 bytes removed ,  12 years ago
m
whitespace
No edit summary
m (whitespace)
Line 6:
 
If the solution on this page is a library solution, see [[MD5/Implementation]] for an implementation from scratch.
 
 
=={{header|Ada}}==
Line 22 ⟶ 21:
===Regular version===
Source: [http://www.autohotkey.com/forum/post-275910.html#275910 AutoHotkey forum] by SKAN
<lang autohotkey>data := "abc"
<br>
<lang autohotkey>
data := "abc"
MsgBox % MD5(data,StrLen(data)) ; 900150983cd24fb0d6963f7d28e17f72
 
Line 35 ⟶ 32:
Return MD5
}
}</lang>
}
</lang>
 
===Native implementation===
Source: [http://www.autohotkey.com/forum/topic17853.html AutoHotkey forum] by Laszlo
<lang autohotkey>; GLOBAL CONSTANTS r[64], k[64]
<br>
<lang autohotkey>
; GLOBAL CONSTANTS r[64], k[64]
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 116 ⟶ 110:
SetFormat Integer, DECIMAL
Return x
}</lang>
}
</lang>
 
=={{Header|BBC BASIC}}==
Line 306 ⟶ 299:
 
=={{header|C sharp|C#}}==
 
<lang csharp>using System.Text;
using System.Security.Cryptography;
Line 315 ⟶ 307:
 
=={{header|Clojure}}==
<lang lisp>(apply str
 
<lang lisp>
(apply str
(map (partial format "%02x")
(.digest (doto (java.security.MessageDigest/getInstance "MD5")
.reset
(.update (.getBytes "The quick brown fox jumps over the lazy dog"))))))</lang>
</lang>
 
=={{header|Common Lisp}}==
 
This one uses a library, but if you want to see how it's implemented, press M-x slime-edit-definition and go to <tt>md5:md5sum-stream</tt>.
 
<lang lisp>(require #+sbcl 'sb-md5 #-sbcl 'md5)
 
Line 364 ⟶ 351:
=={{header|Delphi}}==
If you require a native implementation, look inside the class '''TIdHashMessageDigest5'''. This class is placed in the unit '''IdHashMessageDigest.pas'''.
<lang Delphi>program MD5Hash;
program MD5Hash;
 
{$APPTYPE CONSOLE}
Line 391 ⟶ 377:
Writeln(MD5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'));
Readln;
end.</lang>
</lang>
'''Output:'''
<pre>
Line 405 ⟶ 390:
 
=={{header|E}}==
 
{{works with|E-on-Java}}
 
{{trans|Java}} (with modifications)
 
<lang e>def makeMessageDigest := <import:java.security.makeMessageDigest>
def sprintf := <import:java.lang.makeString>.format
Line 423 ⟶ 405:
=={{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:
<lang Erlang>-module(tests).
-module(tests).
-export([md5/1]).
 
Line 430 ⟶ 411:
string:to_upper(
lists:flatten([io_lib:format("~2.16.0b",[N]) || <<N>> <= erlang:md5(S)])
).</lang>
 
</lang>
Testing it:
<lang erlang>1> c(tests).
1> c(tests).
{ok,tests}
2> tests:md5("The quick brown fox jumped over the lazy dog's back").
"E38CA1D920C4B8B8D3946B2C72F01680"</lang>
</lang>
 
=={{header|Factor}}==
Line 450 ⟶ 427:
=={{header|Forth}}==
{{libheader|Forth Foundation Library}}
<lang forth>include ffl/md5.fs
 
\ Create a MD5 variable md1 in the dictionary
md5-create md1
\ Update the variable with data
s" The quick brown fox jumps over the lazy dog" md1 md5-update
\ Finish the MD5 calculation resulting in four unsigned 32 bit words
\ on the stack representing the hash value
md1 md5-finish
\ Convert the hash value to a hex string and print it
md5+to-string type cr</lang>
 
=={{header|Frink}}==
The <CODE>messageDigest[string, hash]</CODE> returns a hex-encoded hash of any input string with a variety of hashing functions.
<lang frink>println[messageDigest["The quick brown fox", "MD5"]]</lang>
<lang frink>
println[messageDigest["The quick brown fox", "MD5"]]
</lang>
 
=={{header|Go}}==
Line 561 ⟶ 536:
=={{header|J}}==
Using the <tt>[http://www.jsoftware.com/trac/addons/browser/trunk/convert/misc/md5.ijs md5]</tt> script from the <tt>convert/misc</tt> addon package:
<lang j> require 'convert/misc/md5'
require 'convert/misc/md5'
md5 'The quick brown fox jumped over the lazy dog''s back'
e38ca1d920c4b8b8d3946b2c72f01680</lang>
</lang>
 
=={{header|Java}}==
 
Modified from [http://mindprod.com/jgloss/md5.html mindprod's Java Glossary]:
<lang java>import java.io.UnsupportedEncodingException;
Line 716 ⟶ 688:
 
end function
 
 
 
Line 749 ⟶ 720:
 
=={{header|Lua}}==
 
Using the [http://www.keplerproject.org/md5/ Kepler MD5 library]:
 
<lang Lua>require "md5"
 
Line 767 ⟶ 736:
test("abcdefghijklmnopqrstuvwxyz","c3fcd3d76192e4007dfb496cca67e13b")
test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789","d174ab98d277d9f5a5611c2c9f419d9f")
test("12345678901234567890123456789012345678901234567890123456789012345678901234567890","57edf4a22be3c955ac49da2e2107b67a")</lang>
</lang>
 
=={{header|Mathematica}}==
Mathematica has built-in function Hash and FileHash, it should be noted that Hash["hello","MD5"] would give the MD5 of ""hello"" in stead of "hello". This is done because it wants to distinguish between the variable hello and the string "hello". A workaround for getting MD5's from strings would be:
<lang Mathematica> StringHash[string_String]:=Module[{stream=OpenWrite[],file,hash},
StringHash[string_String]:=Module[{stream=OpenWrite[],file,hash},
WriteString[stream,string];
file=Close[stream];
Line 779 ⟶ 746:
DeleteFile[file];
hash
]</lang>
</lang>
Example:
<lang Mathematica> StringHash["The quick brown fox jumped over the lazy dog's back"] // BaseForm[#, 16] &</lang>
<lang Mathematica>
StringHash["The quick brown fox jumped over the lazy dog's back"] // BaseForm[#, 16] &
</lang>
gives back:
<lang Mathematica> e38ca1d920c4b8b8d3946b2c72f01680</lang>
e38ca1d920c4b8b8d3946b2c72f01680
</lang>
 
=={{header|MATLAB}}==
Line 937 ⟶ 899:
end %md5</lang>
 
Sample Usage:
<lang MATLAB>>> md5('The quick brown fox jumps over the lazy dog.')
Line 1,033 ⟶ 994:
end
 
return</lang>
;Output:
</lang>
;Output
<pre>
<Message>The quick brown fox jumps over the lazy dog</Message>
Line 1,117 ⟶ 1,077:
=={{header|OpenEdge/Progres}}==
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.
 
<lang progress>MESSAGE
1 STRING( HEX-ENCODE( MD5-DIGEST( "" ) ) ) SKIP
Line 1,143 ⟶ 1,102:
OK
---------------------------
 
</pre>
 
Line 1,161 ⟶ 1,119:
=={{header|Perl 6}}==
Library [http://github.com/cosimo/perl6-digest-md5/ Digest::MD5]
<lang perl6>use Digest::MD5;
say Digest::MD5.md5_hex: "The quick brown fox jumped over the lazy dog's back";</lang>
use Digest::MD5;
say Digest::MD5.md5_hex: "The quick brown fox jumped over the lazy dog's back";
</lang>
 
=={{header|PHP}}==
 
<lang php>$string = "The quick brown fox jumped over the lazy dog's back";
echo md5( $string );</lang>
Line 1,234 ⟶ 1,189:
 
=={{header|REBOL}}==
<lang rebol>>> checksum/method "The quick brown fox jumped over the lazy dog" 'md5
<lang rebol>
>> checksum/method "The quick brown fox jumped over the lazy dog" 'md5
== #{08A008A01D498C404B0C30852B39D3B8}</lang>
 
=={{header|RLaB}}==
 
RLaB has a built-in function ''hash,''
:<math>hs = hash(fn, s /, nl/) </math>
Line 1,246 ⟶ 1,199:
calculated in RLaB is the same as the hash of the same string vector written to a file.
 
<lang RLaB>>> x = "The quick brown fox jumped over the lazy dog's back"
<lang RLaB>
>> x = "The quick brown fox jumped over the lazy dog's back"
The quick brown fox jumped over the lazy dog's back
 
>> hash("md5", x)
e38ca1d920c4b8b8d3946b2c72f01680</lang>
</lang>
 
=={{header|Ruby}}==
Line 1,260 ⟶ 1,211:
 
=={{header|Slate}}==
 
You must load the code in 'src/lib/md5.slate'.
<lang slate>'The quick brown fox jumped over the lazy dog\'s back' md5String. "==> 'e38ca1d920c4b8b8d3946b2c72f01680'"</lang>
<lang slate>
'The quick brown fox jumped over the lazy dog\'s back' md5String. "==> 'e38ca1d920c4b8b8d3946b2c72f01680'"
</lang>
 
=={{header|Smalltalk}}==
Line 1,273 ⟶ 1,221:
=={{header|SQL}}==
{{works with|MySQL}}
 
<lang sql>SELECT MD5('The quick brown fox jumped over the lazy dog\'s back')</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.