[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] decode letter scrambling "kode"



"Michael Schmidt" <sslug@sslug> writes:

> Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer
> in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is

[...]

> Men er det overhovedt muligt at lave en automatiseret dekodning?

Jeg er sikker på at man kan finde eksempler på ord hvor man ikke uden
kontekst kan dekode ordet entydigt. Men med en passende ordliste tror
jeg at det er ganske let at lave.

For sjov smed jeg lige teksten gennem ispell og aspell. Ispell med den
britiske ordliste var ikke noget at skrive hjem om, men i de fleste
tilfælde havde aspell det rigtige ord med blandt mulighederne. Det
overrasker mig faktisk en smule at det ikke var omvendt.

Men jeg tror et håndkodet opslag i en ordliste ville have en meget
bedre hitrate. Prøv nedenstående. Koden tager ikke hensyn til store og
små bogstaver, så der er to forventede fejl (According og
University). De resterende fejl jeg får er stavefejl i originalen.


#!/usr/bin/perl

sub getkey {
    my $w = shift;

    my $key;
    $key .= substr $w, 0, 1;
    $key .= substr $w, -1, 1;
    $key .= join "", sort split "", substr($w, 1, length($w)-2);

    return $key;
}

my %dictionary;
open my $dictfile, '<', '/usr/share/dict/british-english';
while( <$dictfile> ) {
    chomp;
    my $key = getkey $_;

    warn "Collision $dictionary{$key} ~ $_" if exists
    $dictionary{$key} and $ENV{DEBUG};
    $dictionary{$key} = $_;
}

while(<>) {

    s{ (\w+) }
     {
         my $key = getkey $1;
         exists $dictionary{$key} ? $dictionary{$key} : $1;
     }gex;

     print;

}

__END__    


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2008-02-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *