Ja bih rekao: [i]Zenbakia kantitate baten irudia edo sinboloa da.[/i]
Naime, gledao sam međusobni indeks koincidencije engleskog teksta i šifrata s abecedom pomaknutom redom za 0, 1, 2, ..., 25.
Evo rezultata:
[code:1]0 0.025
1 0.037
2 0.030
3 0.042
4 0.042
5 0.044
6 0.038
7 0.038
8 0.036
9 0.044
10 0.043
11 0.029
12 0.046
13 0.036
14 0.032
15 0.033
16 0.041
17 0.034
18 0.039
19 0.058
20 0.043
21 0.023
22 0.037
23 0.067
24 0.038
25 0.027[/code:1]
Uočavamo da je indeks 0.067 najveći za pomak 23. Dakle, ako pomaknemo abecedu šifrata za 23, dobijemo (najvjerojatnije) originalni tekst, ili ako pomaknemo originalni tekst za 3, dobijemo šifrat.
To je zapravo obična Cezarova šifra iz davnih vremena. A->D, B->E, ...
Evo i koda u C-u koji izbacuje gornji rezultat:
[code:1]/* Autor: Filip Niksic */
#include <stdio.h>
double freq_engl[] = {
0.082, 0.015, 0.028, 0.043, 0.127, 0.022, 0.020, 0.061, 0.070, 0.002,
0.008, 0.040, 0.024, 0.067, 0.075, 0.019, 0.001, 0.060, 0.063, 0.091,
0.028, 0.010, 0.023, 0.001, 0.020, 0.001
};
int main(int argc, char **argv) {
FILE *in;
int pomak,i,n;
int freq[26];
char c;
double mic;
if (argc<2 || (in=fopen(argv[1],"r"))==NULL) {
printf("Couldn't open input file!\n");
return 0;
}
for (i=0,n=0;i<26;freq[i++]=0);
while (!feof(in)) {
fscanf(in,"%c",&c);
if (c>='a' && c<='z') c-='a'-'A';
if (c>='A' && c<='Z') {
c-='A';
freq[c]++;
n++;
}
}
for (pomak=0;pomak<26;pomak++) {
mic=0.0;
for (i=0;i<26;i++)
mic+=freq_engl[i]*(double)freq[(i+pomak)%26];
mic/=(double)n;
printf("%d %.3lf\n",pomak,mic);
}
fclose(in);
return 0;
}[/code:1]
Ja bih rekao: Zenbakia kantitate baten irudia edo sinboloa da.
Naime, gledao sam međusobni indeks koincidencije engleskog teksta i šifrata s abecedom pomaknutom redom za 0, 1, 2, ..., 25.
Evo rezultata:
Kod: | 0 0.025
1 0.037
2 0.030
3 0.042
4 0.042
5 0.044
6 0.038
7 0.038
8 0.036
9 0.044
10 0.043
11 0.029
12 0.046
13 0.036
14 0.032
15 0.033
16 0.041
17 0.034
18 0.039
19 0.058
20 0.043
21 0.023
22 0.037
23 0.067
24 0.038
25 0.027 |
Uočavamo da je indeks 0.067 najveći za pomak 23. Dakle, ako pomaknemo abecedu šifrata za 23, dobijemo (najvjerojatnije) originalni tekst, ili ako pomaknemo originalni tekst za 3, dobijemo šifrat.
To je zapravo obična Cezarova šifra iz davnih vremena. A→D, B→E, ...
Evo i koda u C-u koji izbacuje gornji rezultat:
Kod: | /* Autor: Filip Niksic */
#include <stdio.h>
double freq_engl[] = {
0.082, 0.015, 0.028, 0.043, 0.127, 0.022, 0.020, 0.061, 0.070, 0.002,
0.008, 0.040, 0.024, 0.067, 0.075, 0.019, 0.001, 0.060, 0.063, 0.091,
0.028, 0.010, 0.023, 0.001, 0.020, 0.001
};
int main(int argc, char **argv) {
FILE *in;
int pomak,i,n;
int freq[26];
char c;
double mic;
if (argc<2 || (in=fopen(argv[1],"r"))==NULL) {
printf("Couldn't open input file!\n");
return 0;
}
for (i=0,n=0;i<26;freq[i++]=0);
while (!feof(in)) {
fscanf(in,"%c",&c);
if (c>='a' && c<='z') c-='a'-'A';
if (c>='A' && c<='Z') {
c-='A';
freq[c]++;
n++;
}
}
for (pomak=0;pomak<26;pomak++) {
mic=0.0;
for (i=0;i<26;i++)
mic+=freq_engl[i]*(double)freq[(i+pomak)%26];
mic/=(double)n;
printf("%d %.3lf\n",pomak,mic);
}
fclose(in);
return 0;
} |
_________________ I don't know half of you half as well as I should like; and I like less than half of you half as well as you deserve.
Zadnja promjena: Melkor; 23:19 uto, 20. 3. 2007; ukupno mijenjano 1 put.
|