
yellowman
Novice
Dec 13, 2006, 1:08 PM
Post #5 of 7
(646 views)
|
|
Re: [yellowman] Perl Substitution variable
[In reply to]
|
Can't Post
|
|
Well, I'm closer than I was before, but it only seems to unencrypt 1 or two elements out of each string. A copy of the encrypted file and the key are attached. Here is the complete code: #!/usr/local/bin/perl print ("What is the dictionary filename (.dict)? "); $d_file = <STDIN>; unless (open (DICT, $d_file)) { die ("The selected file cannot be found"); } @dict = <DICT>; print ("What is the Usage Report filename (.txt)? "); $t_file = <STDIN>; unless (open (TEXT, $t_file)) { die ("The selected file cannot be found"); } @txt = <TEXT>; &cleanup (@txt); &compare(@txt, @dict); sub cleanup { my ($count) = 0; my ($index) = 0; my ($string); my ($size1); my @temp_array; my @temp_array1; while ($txt[$count] ne ""){ if ($txt[$count] =~ /^A[CB]/) { $temp_array[$index] = $txt[$count]; $index++; } $count++; } @txt = @temp_array; $size1 = @txt; for($index=0; $index <= ($size1-1); $index++){ $string = $txt[$index]; $string =~ tr/(|)|,//d; @temp_array1[$index] = $string; } @txt = @temp_array1; } sub compare { my ($count); my ($index); my ($work1); my ($work2); my ($size1); my ($size2); my @temp_array1; my @temp_array2; my @temp_array3; $size1 = @dict; for($count=0; $count <= ($size1-1); $count++){ $string = $dict[$count]; @temp_array1 = split(/ +/, $string); @temp_array2 = @txt; $size2 = @temp_array2; for($index=0; $index <= ($size2-1); $index++){ $work1 = $temp_array1[1]; $work2 = $temp_array2[$index]; chop($work1); if ($work2 =~ /$work1/){ $work2 =~ s/$work1/$temp_array1[0]/gx; $temp_array3[$index] = $work2; } } } print("@temp_array3\n"); } It has to be something small that I am overlooking. It's as if my loops don't go through enough iterations to decrypt the contents or the txt file.
|