Skip to content

Instantly share code, notes, and snippets.

@masak
Forked from anonymous/perl6.pl
Created October 24, 2010 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/643769 to your computer and use it in GitHub Desktop.
Save masak/643769 to your computer and use it in GitHub Desktop.
# http://www.elliottkember.com/kember_identity.html
use v6;
pir::load_bytecode('Digest/MD5.pir');
my Int $count = 0;
my Str @alphabet = (0..9, 'a'..'f');
my Str $string = @alphabet.roll(32).join;
loop {
my Str $md5 = md5_hex($string);
if ($md5 === $string) {
say "We have a winner after testing $count strings!";
say "md5($string) = $md5";
exit;
}
if ((++$count % 10) === 0) {
say "{$count/10}: md5($string) = $md5";
}
$string = $md5;
}
sub md5_hex (Str $str) {
return Q:PIR {
.local pmc f, g, str
str = find_lex '$str'
f = get_root_global ['parrot'; 'Digest'], '_md5sum'
$P1 = f(str)
g = get_root_global ['parrot'; 'Digest'], '_md5_hex'
$S0 = g($P1)
%r = box $S0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment