#!/usr/bin/perl # #The Arbitrary Text Code 2.0a #by Leonard Richardson leonardr@ucla.edu # #Execute with: tatc [regexp] [file] # #TATC will read in [file] and attempt to find a string matching #[regexp] with the characters some number of spaces apart. It does #this by inserting a ".{x}" between each character of your regexp, for #a large range of x, so things like * won't make sense. I think you #should stick to plain strings. # #Bugs: #* The program will currently find at most one match for each skip. # Eventually I'll fix it to find all matches for a given skip. # #* Negative skip is not supported. It will eventually be supported by # simply reversing the string and finding an encoding of that with # positive skip. ($string,$path) = @ARGV; #Set this to 0 if you don't want status messages. $status = 1; #Grab the text into a string. open TEXT, $path or die "Can't open file $path."; while () {$text .= $_;} $len = length($text); for ($i = 0; $i <= 1000; $i++) { #If it's a bunch of text, print out status mesasges every ten skips. if ($len > 100000 && ($i % 10) == 0 && $status) { print "$i...\n"; } $base_regexp = ".{$i}"; $regexp = ""; for ($j = 0; $j < length($string); $j++) { $regexp .= substr($string,$j,1) . $base_regexp; } if ($text =~ /$regexp/i) { $matched_text = $&; print "Found with skip $i:\n"; for ($line = 0; $line < length($string); $line++) { $linelen = min($i+1,77); if ($i+1 > 77) { $suffix = "...";} print substr($matched_text,$line*($i+1),$linelen); print $suffix; print "\n"; } } } sub min{($a,$b)=@_;if($a<$b){$a;}else{$b;}}