Hackthissite - Program Level 1

之前用excel run 個 script , 而家用返perl 寫返個program


#!/usr/bin/perl -w

use strict;
my %wordlist;
my %reversewordlist;
my @hackwordw;
my $i=-1;
my $hackword;
my %hashwordlist=(
"0" => 2,
"1" => 3,
"2" => 5,
"3" => 7,
"4" => 11,
"5" => 13,
"6" => 17,
"7" => 19,
"8" => 23,
"9" => 29,
"a" => 31,
"b" => 37,
"c" => 41,
"d" => 43,
"e" => 47,
"f" => 53,
"g" => 59,
"h" => 61,
"i" => 67,
"j" => 71,
"k" => 73,
"l" => 79,
"m" => 83,
"n" => 89,
"o" => 97,
"p" => 101,
"q" => 103,
"r" => 107,
"s" => 109,
"t" => 113,
"u" => 127,
"v" => 131,
"w" => 137,
"x" => 139,
"y" => 149,
"z" => 151,
":" => 157,
")" => 163,
";" => 167);

open(FHD, "< wordlist.txt") || die "$!\n";
while (chomp(my $line=)) {
$wordlist{trim($line)}=hashofwordlist(trim($line));
%reversewordlist=reverse %wordlist;
}
close(FHD);

print "Wordlist Uploaded. Input Keyword pls\n";

do {
$i++;
chomp($hackword=);
$hackword =~ s/#//;
$hackword= trim($hackword);
push @hackwordw, $hackword;
} until ($hackword eq '' );
pop @hackwordw;

my $m;
my $n;
my $resultval;

foreach $m (@hackwordw) {
$resultval = hashofwordlist($m);
$n=$reversewordlist{$resultval};
print $n,',';
}
print "\n";
exit;

sub hashofwordlist {
my $s=$_[0];
my $result=1;
my $i;
my $a;
my $b;
for ($i=0;$i<(length($s));$i++){
$a=(substr $s, $i, 1);
$b=$hashwordlist{"$a"};
$result *= $b;
}
return $result;
}


# Perl trim function to remove whitespace from the start and end of the string
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
# Left trim function to remove leading whitespace
sub ltrim($)
{
my $string = shift;
$string =~ s/^\s+//;
return $string;
}
# Right trim function to remove trailing whitespace
sub rtrim($)
{
my $string = shift;
$string =~ s/\s+$//;
return $string;
}

Comments

Popular Posts