Matrix Example

#!/usr/bin/perl
#
# Example of using a matrix in perl
#
# During a penetration test a trove of obfuscated SSNs was discovered.
# Once the positional and substitution methods were deduced, this script was created to deobfuscate all SSNs.

open(ENC, "< all_enc.txt"); # expected input filename containing encoded SSNs, one per line
open(OUT, "> decoded_ssn.txt"); #default output file name containing encoded and decoded SSNs

	@matrix = (
			[6,6,5,9,9,8,8,8,X],
			[4,4,7,7,7,7,7,7,X],
			[3,3,6,6,2,2,2,2,2],
			[2,2,8,3,5,4,5,4,4],
			[1,1,9,1,1,1,1,0,1],
			[9,9,0,2,6,0,0,1,0],
			[7,0,3,8,8,9,9,9,7],
			[0,8,2,4,0,6,6,6,6],
			[5,5,1,5,3,5,4,5,5],
			[8,7,4,0,4,3,3,3,3]
          ); #the matrix of encoded to decoded SSNs

	@ssn_pos = (9, 2, 7, 4, 5, 6, 3, 8, 1); #used to change encoded SSN position to decoded SSN position

print OUT "Encoded SSN\tDecoded SSN\n";

	while (<ENC>) {
	chomp;
	print OUT "$_\t";
	@nums = split(undef,$_); #split encoded SSN into separate values for processing
	$i=0;
	foreach $num (@nums) { #for each encoded SSN position
		$ssn[$ssn_pos[$i]] = $matrix[$num][$i]; #find value in matrix and place in decoded SSN position
		$i++;
	  		}
	print OUT @ssn;
	print OUT "\n";
			}

Leave a Reply

Your email address will not be published. Required fields are marked *