javascript - Stuck on Converting a JS function to Perl -
im trying convert this: (js function) perl.
decrypt3 = function (strin, strkey) { var strout = new string(); var lenin = strin.length; var lenkey = strkey.length; var = 0; var numin; var numkey; while (i < lenin) { numin = parseint(strin.substr(i, 2), 32); numkey = strkey.charcodeat(i / 2 % lenkey); strout += string.fromcharcode(numin - numkey); += 2; } return strout; };
this far have come: im not sure how strout , correct numkey.
while (<>) { chomp; print decrypt3($_, $key),"\n"; } sub decrypt3 { @str_in = unpack 'c*', shift; @str_key = unpack 'c*', shift; @str_out; $i (0 .. $str_in) { $numin = int[$str_in[ord[$i 2], 32] $sum = $str_in[$i] + $str_key[$i / 2% @str_key];
use list::util 1.29 qw( pairmap ); @base32_syms = (0..9, 'a'..'v'); %base32_sym_vals = map { lc($base32_syms[$_]) => $_, uc($base32_syms[$_]) => $_, } 0..$#base32_syms; sub decrypt3 { @cypher = pairmap { $base32_sym_vals{$a} * 32 + $base32_sym_vals{$b} } split(//, shift); @key = unpack('c*', shift); return join ' ', map { chr($cypher[$_] - $key[ $_ % @key ]) } 0..$#cypher; }
Comments
Post a Comment