RosettaCodeData/Task/MD5/Nemerle/md5.nemerle
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

34 lines
1.3 KiB
Text

using System;
using System.Console;
using System.Text;
using System.Security.Cryptography;
using Nemerle.Collections;
using Nemerle.Collections.NCollectionsExtensions;
module Md5
{
HashMD5(input : string) : string
{
BitConverter.ToString
(MD5.Create().ComputeHash(Encoding.Default.GetBytes(input))).Replace("-", "").ToLower()
}
IsValidMD5(text : string, hash : string) : bool
{
HashMD5(text) == hash.ToLower()
}
Main() : void
{
def examples = ["The quick brown fox jumped over the lazy dog's back", "", "a", "abc", "message digest",
"abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"];
def hashes = ["e38ca1d920c4b8b8d3946b2c72f01680", "d41d8cd98f00b204e9800998ecf8427e",
"0cc175b9c0f1b6a831c399e269772661", "900150983cd24fb0d6963f7d28e17f72",
"f96b697d7cb7938d525a2f31aaf161d0", "c3fcd3d76192e4007dfb496cca67e13b",
"d174ab98d277d9f5a5611c2c9f419d9f", "57edf4a22be3c955ac49da2e2107b67a"];
def tests = Hashtable(ZipLazy(examples, hashes));
foreach (test in tests)
Write($"$(IsValidMD5(test.Key, test.Value)) ");
}
}