SyntaxErr0r
10-04-2007, 06:30 PM
I put this script together while learning Perl (still a newbie), and also want to contribute back to the community for the knowledge I am getting.
The script has room for expansion and growth. Hope this help someone.
#!/usr/bin/perl -w
#
# Wordlist manipulator, generator
# By 0xyCont1n
#
use Getopt::Std;
#
# Message about how to use this script
#
sub usage(){
print STDERR << "EOF";
Worldlist manipulator by 0xyCont1n.
Usage: Wmanip [options] filename
Options:
-h Help message (this)
-w file Output filename
-d word Append your word at the end
-p word Prepend your word at the begining
-A Apply all the condition below
-e Replace e by 3
-s Replace s by 2 and 5
-a Replace a by @ and 4
-i Replace i by 1
-g Replace g by 5
-t Replace t by 7
-B Replace B by 8
-o Replace o by 0
-r Reverse word
-l Lowercase word
-u Uppercase word
-U First letter uppercase
Example: Wmanip -A -d 123 filename
EOF
exit;
}
#Get command line argument
getopts( "AhesaigtBorluUw:p:d:", \%opt ) or usage();
usage() if $opt{h};
usage() unless ( $ARGV[0] and %opt );
#check if the file exist
if ( ! -f $ARGV[0] ) { die "Seems like the file: '$ARGV[0]' doesn't exist!\nPlease try again.\n:( :(\n"; }
# Get the arguments
my $file = $ARGV[0];
my $temp = "$file.swp";
my $outfile = undef;
if ( defined $opt{w}) {
$outfile = $opt{w};
}else{ $outfile = "result.txt"; } # default file output
open ( INFILE, $file) or die "Couldn't open file: $file\n";
open ( OUTFILE, ">$temp");
#Loop through the content of the file, line by line
while ( <INFILE> ){
chomp; #Get ride of new line
s/^\s+//; #Remove leading whitespace
s/\s+$//; #Remove trailing whitespace
print OUTFILE "$_\n";
# start the manipulation of word here
# Lowercase
if ( defined $opt{A} or defined $opt{l} ){
print OUTFILE "\L$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\L$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\L$_$opt{d}\n"; }
}
# First letter upper case
if ( defined $opt{A} or defined $opt{U} ){
print OUTFILE "\u$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# Uppercase
if ( defined $opt{A} or defined $opt{u} ){
print OUTFILE "\U$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\U$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\U$_$opt{d}\n"; }
}
# Reverse the word
if ( ( defined $opt{r} or defined $opt{A} ) and length($_) > 1 ){
my $r = reverse $_ ;
print OUTFILE "$r\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$r\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$r$opt{d}\n"; }
}
# Character replacement
# a -> @ | 4
if ( defined $opt{A} or defined $opt{a} ){
if ( tr/a/\@/ ) {
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
if ( tr/a/4/) {
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
}
# e -> 3
if ( tr/e/3/ and ( defined $opt{A} or defined $opt{e} ) ){
print OUTFILE "$_\n" ;
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# s -> 2 | 5
if ( defined $opt{A} or defined $opt{s} ){
if ( tr/s/2/ ) { print OUTFILE "$_\n"; }
if ( tr/s/5/ ) { print OUTFILE "$_\n"; }
}
# i -> 1
if ( tr/i/1/ and ( defined $opt{A} or defined $opt{i} ) ){
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# g -> 5
if ( tr/g/5/ and ( defined $opt{A} or defined $opt{g} ) ){
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# t -> 7
if ( tr/t/7/ and ( defined $opt{A} or defined $opt{t} ) ){
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# o -> 0
if ( tr/o/0/ and ( defined $opt{A} or defined $opt{o} ) ){
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# B - 8
if ( tr/B/8/ and ( defined $opt{A} or defined $opt{B} ) ){
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
} # End of while loop ( end of reading the file)
close (INFILE);
close (OUTFILE);
# Sorting and removal of duplicate entries
system ("uniq $temp | sort -f > $outfile");
# Deleting temporary created file
unlink($temp);
print "Finished !!!\nOutput in file: $outfile \n";
The script has room for expansion and growth. Hope this help someone.
#!/usr/bin/perl -w
#
# Wordlist manipulator, generator
# By 0xyCont1n
#
use Getopt::Std;
#
# Message about how to use this script
#
sub usage(){
print STDERR << "EOF";
Worldlist manipulator by 0xyCont1n.
Usage: Wmanip [options] filename
Options:
-h Help message (this)
-w file Output filename
-d word Append your word at the end
-p word Prepend your word at the begining
-A Apply all the condition below
-e Replace e by 3
-s Replace s by 2 and 5
-a Replace a by @ and 4
-i Replace i by 1
-g Replace g by 5
-t Replace t by 7
-B Replace B by 8
-o Replace o by 0
-r Reverse word
-l Lowercase word
-u Uppercase word
-U First letter uppercase
Example: Wmanip -A -d 123 filename
EOF
exit;
}
#Get command line argument
getopts( "AhesaigtBorluUw:p:d:", \%opt ) or usage();
usage() if $opt{h};
usage() unless ( $ARGV[0] and %opt );
#check if the file exist
if ( ! -f $ARGV[0] ) { die "Seems like the file: '$ARGV[0]' doesn't exist!\nPlease try again.\n:( :(\n"; }
# Get the arguments
my $file = $ARGV[0];
my $temp = "$file.swp";
my $outfile = undef;
if ( defined $opt{w}) {
$outfile = $opt{w};
}else{ $outfile = "result.txt"; } # default file output
open ( INFILE, $file) or die "Couldn't open file: $file\n";
open ( OUTFILE, ">$temp");
#Loop through the content of the file, line by line
while ( <INFILE> ){
chomp; #Get ride of new line
s/^\s+//; #Remove leading whitespace
s/\s+$//; #Remove trailing whitespace
print OUTFILE "$_\n";
# start the manipulation of word here
# Lowercase
if ( defined $opt{A} or defined $opt{l} ){
print OUTFILE "\L$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\L$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\L$_$opt{d}\n"; }
}
# First letter upper case
if ( defined $opt{A} or defined $opt{U} ){
print OUTFILE "\u$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# Uppercase
if ( defined $opt{A} or defined $opt{u} ){
print OUTFILE "\U$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\U$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\U$_$opt{d}\n"; }
}
# Reverse the word
if ( ( defined $opt{r} or defined $opt{A} ) and length($_) > 1 ){
my $r = reverse $_ ;
print OUTFILE "$r\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$r\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$r$opt{d}\n"; }
}
# Character replacement
# a -> @ | 4
if ( defined $opt{A} or defined $opt{a} ){
if ( tr/a/\@/ ) {
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
if ( tr/a/4/) {
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
}
# e -> 3
if ( tr/e/3/ and ( defined $opt{A} or defined $opt{e} ) ){
print OUTFILE "$_\n" ;
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# s -> 2 | 5
if ( defined $opt{A} or defined $opt{s} ){
if ( tr/s/2/ ) { print OUTFILE "$_\n"; }
if ( tr/s/5/ ) { print OUTFILE "$_\n"; }
}
# i -> 1
if ( tr/i/1/ and ( defined $opt{A} or defined $opt{i} ) ){
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# g -> 5
if ( tr/g/5/ and ( defined $opt{A} or defined $opt{g} ) ){
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# t -> 7
if ( tr/t/7/ and ( defined $opt{A} or defined $opt{t} ) ){
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# o -> 0
if ( tr/o/0/ and ( defined $opt{A} or defined $opt{o} ) ){
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
# B - 8
if ( tr/B/8/ and ( defined $opt{A} or defined $opt{B} ) ){
print OUTFILE "$_\n";
if ( defined $opt{p} and $opt{p} ne ''){ print OUTFILE "\u$opt{p}$_\n"; }
if ( defined $opt{d} and $opt{d} ne ''){ print OUTFILE "\u$_$opt{d}\n"; }
}
} # End of while loop ( end of reading the file)
close (INFILE);
close (OUTFILE);
# Sorting and removal of duplicate entries
system ("uniq $temp | sort -f > $outfile");
# Deleting temporary created file
unlink($temp);
print "Finished !!!\nOutput in file: $outfile \n";