mathe
发表于 2008-3-7 14:44:39
统计结果表示那个数据有问题,自然无法解开。
我认为要么那个数据有误,要么就是加密算法有问题,或者数据不是来源于英文。
lmax
发表于 2008-3-7 17:53:46
我想问一下这个 $chi^2$叫什么,怎么念,英文应该叫什么???
BTW, 我想问一下,相减后,如果不除以Pn会怎么样呢?好像也可以呀?
就是直接 fabs (standard_freq - cipher_freq)会如何?
mathe
发表于 2008-3-7 19:23:21
$chi^2$是希腊字母,应该就按这个希腊字母发音,所以就叫Chi Square。
不除以$p_n4$是也可以看成一个准则,但是不同部分权重不同,没有除以$p_n$后的好,而且最重要的是$chi^2$是一个很重要的分布,所以结果很好处理
mathe
发表于 2008-3-8 10:04:14
关于$chi^2$分布,可以查看http://mathworld.wolfram.com/Chi-SquaredDistribution.html
荼靡破晓
发表于 2012-4-15 18:44:55
购买了竟然不能阅读!
荼靡破晓
发表于 2012-4-15 19:06:14
要是有java版的就好了。。
yy31742
发表于 2014-5-10 17:41:32
金币是够的,怎么TM不能下载,草!
yy31742
发表于 2014-5-14 16:57:53
看不到代码,看不到代码。。。。。。。
yy31742
发表于 2014-5-14 17:10:07
靠,我购买了附件怎么不能下载呢
mathe
发表于 2021-5-2 19:21:17
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
const char *raw = "BZWIEZSEHPVCIEBSYHAWWYLIIGWHMILZLMHTCSXWWCWXWWJLEIWOLMBSWPXWWXSVTZPWEXVESXWWXPMHLPRXDLSMWSJPEQXZLHATOPVIQAYHMCYDLIPNPWSUUZVRDMEMRIZPJMTDOALTFDYHSWYPCBQDLIPXCSWTSYHWIGZHYEJTKLIOSMPTQZYVHZPEZTKREXWWCIHGGFRHBAYIECVMSATVOSACLZMXWADFVDLSIVHKLMHIGSMQSGJSYXFEIRSLZVIXYYSZTJFWAXDWCSJSNXYPDWCVJDPYWPFOXLTQSEXTVSMQPDWXLTEZVIQWNEYHWZJLXKOVIPELRHLZLXLTZLHWPAO";
#define KEY_LEN 12
#define NUMC 26
char freq;
int count;
double prob={0.0788,0.0156,0.0268,0.0389,0.1268,0.0256,0.0187,0.0573,0.0707,0.0010,0.0060,0.0394,0.0244,0.0706,0.0776,0.0186,0.0009,0.0594,0.0634,0.0978,0.0280,0.0102,0.0214,0.0016,0.0202,0.0006};
int main()
{
int len=strlen(raw);
int key_len = 5;
int i,j,k;
double entropy=0.0;
double var=0.0;
for(i=0;i<NUMC;i++){
entropy-=prob*log(prob);
var+=prob*log(prob)*log(prob);
}
for(i=0;i<len;i++){
char c=raw;
if('a'<=c&&c<='z'){
freq++;
}else if('A'<=c&&c<='Z'){
freq++;
}else{
fprintf(stderr, "Invalid char %c encounted\n",c);
}
count++;
}
for(i=0;i<KEY_LEN;i++){
double best_entropy = 0;
int best_j=-1;
for(j=0;j<NUMC;j++){
double real_entropy=0.0;
for(k=0;k<NUMC;k++){
real_entropy-=freq[(j+k)%NUMC]*log(prob);
}
if(best_j<0||real_entropy<best_entropy){
best_j=j;
best_entropy=real_entropy;
}
}
double exp_entropy = count*entropy;
double exp_var = count*var;
exp_var = sqrt(exp_var-exp_entropy*exp_entropy/count);
if(best_entropy>exp_entropy+4*exp_var){
fprintf(stderr, "\nNo valid solution found\n");
exit(-1);
}else{
printf("%c",'A'+best_j);
}
}
printf("\n");
return 0;
}