| Category: | Cryptography and Text Processing |
| Author/Contact Info | Will Stockwell (waldo@cyberspace.org) |
| Description: | Updated as of March 16, 2001 at 0120 UTC Does frequency analysis of a monoalphabetic enciphered message via STDIN. (Thanks to Adam for the $i catch). |
#!/usr/bin/perl -w
# Frequency Analyzer by Will Stockwell (waldo@cyberspace.org)
# Big Willy on perlmonks.org
# Thanks to japhy for the split //, lc business
# Thanks to Adam for the $i catch
my %letters;
while (<STDIN>) {
$letters{$_}++ for split //, lc;
}
foreach (sort keys %letters) {
if($_ eq "\n") {
print "\\n";
} elsif($_ eq ' ') {
print "<space>";
} elsif($_ eq "\t") {
print "\\t";
} else {
print "$_";
}
print " = $letters{$_}\n";
}
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Frequency Analyzer
by japhy (Canon) on Mar 16, 2001 at 20:38 UTC | |
|
Re: Frequency Analyzer
by Chmrr (Vicar) on Mar 16, 2001 at 06:27 UTC | |
|
Re: Frequency Analyzer
by merlyn (Sage) on Mar 16, 2001 at 04:38 UTC | |
|
Re: Frequency Analyzer
by Adam (Vicar) on Mar 16, 2001 at 06:08 UTC |