Skip to content

Instantly share code, notes, and snippets.

@ab5tract
Forked from cognominal/sha1.p6
Last active December 11, 2015 19:30
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 ab5tract/20c489d20f289af31533 to your computer and use it in GitHub Desktop.
Save ab5tract/20c489d20f289af31533 to your computer and use it in GitHub Desktop.
sha1 hash
subset Sha1 of Str where *.chars == 40 and m:i/<[A..Z 0..9]>/;
class Sha1H does Associative {
has $!sha1;
has %!h{Sha1(Str)};
method AT-KEY($_) { %!h{ .lc } };
method ASSIGN-KEY($_, $v) { %!h{ .lc } = $v }
}
class Sha1Str is Str {
method Sha1 {
(('a'..'z').pick(10) X (^10).pick(10)).roll(20).flat.join;
}
}
my %h is Sha1H;
my $sha1 = Sha1Str.new; # '64B0F6C3681E428CCE2EB830B05F27B3D7ED643';
say $sha1.Sha1;
%h{$sha1} = 'a';
say %h{$sha1};
%h<a> = 'b';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment