I've ended up with this for now.
cat shafile | perl mkvectors.pl
set_mask(); while (<STDIN>) { chomp; $in = substr($_, 0, 40); if ($in =~ /^[0-9a-f]/i ) { # check that it's valid hex my $in_bits = unpack("B*", pack("H40",$in)); my %offsets ; for(my $j=0;$j<20;$j++) { # each of 20 bitmasks $offsets{calc_vector($in_bits,$bits[$j])} = 1; } foreach my $k (sort {$a <=> $b} (keys %offsets) ) { print "$k\n"; } } } print "\n"; exit; #-------- sub set_mask { $mask[0]="FFFF804020100804020100804020100804000102"; $mask[10]=reverse($mask[0]); $bits[0] = unpack("B*", pack("H40",$mask[0])); $bits[10] = unpack("B*", pack("H40",$mask[10])); for (my $i=1;$i<10;$i++) { $mask[$i] = substr($mask[$i-1],36,4) . substr($mask[$i-1],0,36 +) ; $mask[10+$i] = substr($mask[10+$i-1],36,4) . substr($mask[10+$ +i-1],0,36) ; $bits[$i] = unpack("B*", pack("H40",$mask[$i])); $bits[10+$i] = unpack("B*", pack("H40",$mask[10+$i])); } return(0); } sub calc_vector { my $input = shift; my $mask = shift; my $vecs = ""; for (my $i=0;$i<160;$i++) { if (substr($mask,$i,1) eq "1") { $vecs .= substr($input,$i,1); } } return(hex(unpack("H*", pack("B32",$vecs)))); }

In reply to Re: bitmask to vector problem by dwhite20899
in thread bitmask to vector problem by dwhite20899

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.