A small sub to decode the output from a :Cue:Cat barcode scanner.
# ============ # CueCatDecode # ============ # # Arguments: 1 - output from CueCat scanner # # Returns: An array, structured like this: # $array[0] = CueCat ID # $array[1] = Type of barcode # $array[2] = Barcode data # # Example: # # my $data=<STDIN>; # my @barcode=CueCatDecode($data); # print "ID: $barcode[0]\n"; # print "TYPE: $barcode[1]\n"; # print "BARCODE: $barcode[2]\n"; # sub CueCatDecode { my($cuecat_output)=@_; my $len; my $i; my $c; # Lets Split our CuCat String into a Array with all the differnt s +ubsections my @scanned_data=split /\./,$cuecat_output; # Swap upper case to lower case and vice versa, minuses to slashes my $id = $scanned_data[1]; $id =~ tr|A-Za-z\-|a-zA-Z/|; $id =~ tr|A-Za-z0-9+/| -_|; # convert to uuencode format $len = chr(32+length($id)*3/4); # compute length byte $id = unpack("u", $len . $id); # uudecode my $barcode_type = $scanned_data[2]; $barcode_type =~ tr|A-Za-z\-|a-zA-Z/|; $barcode_type =~ tr|A-Za-z0-9+/| -_|; # convert to uuencode +format $len = chr(32+length($barcode_type)*3/4); # compute length byte $barcode_type = unpack("u", $len . $barcode_type); # uudecode my $barcode = $scanned_data[3]; $barcode =~ tr|A-Za-z\-|a-zA-Z/|; $barcode =~ tr|A-Za-z0-9+/| -_|; # convert to uuencode forma +t $len = chr(32+length($barcode)*3/4); # compute length byte $barcode = unpack("u", $len . $barcode); # uudecode # Take each character XOR 67 my $decrypt_id=''; for ($i=0;$i<length($id);$i++) { $c = substr($id,$i,1); $decrypt_id = $decrypt_id . chr(ord($c) ^ 67); } my $decrypt_type=''; for ($i=0;$i<length($barcode_type);$i++) { $c = substr($barcode_type,$i,1); $decrypt_type = $decrypt_type . chr(ord($c) ^ 67); } my $decrypt_barcode=''; for ($i=0;$i<length($barcode);$i++) { $c = substr($barcode,$i,1); $decrypt_barcode = $decrypt_barcode . chr(ord($c) ^ 67); } my @decrypted_barcode=(); push(@decrypted_barcode,$decrypt_id); push(@decrypted_barcode,$decrypt_type); push(@decrypted_barcode,$decrypt_barcode); return @decrypted_barcode; }

In reply to CueCat Decoding Sub by #include

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.