+sub _blind_len ($$) {
+ my ($r, $str) = @_;
+ return length($str =~ y/0-9a-f//cdr);
+}
+
+sub _blind_combine ($$$) {
+ my ($r, $in, $mask) = @_;
+ my @mask = split //, $mask;
+ $in =~ s{[0-9a-f]}{
+ my $m = shift @mask;
+ sprintf "%x", hex($m) ^ hex($&);
+ }ge;
+ return $in;
+}
+
+sub _blind ($$) {
+ my ($r, $in) = @_;
+ return $in unless $in;
+ my $l = $r->_blind_len($in);
+ my $mask = $r->_random(($l+1)>>1);
+ $mask = substr $mask, 0, $l;
+ my $blound = $r->_blind_combine($in, $mask);
+ return "$blound.$mask";
+}
+
+sub _unblind ($$) {
+ my ($r, $in) = @_;
+ return $in unless $in;
+ my ($blound,$mask) = ($in =~ m#^(.*)\.([0-9a-f]+)$#) or die "$in ?";
+ my $l = $r->_blind_len($blound);
+ $l == length($mask) or die "$in ?";
+ return $r->_blind_combine($blound, $mask);
+}
+