您的位置:首页 > 其它

POJ 2159 Ancient Cipher 解题报告

2007-05-23 13:21 609 查看
substitution cipher (置换密码):

Substitution cipher changes all occurrences of each letter to some other letter. Substitutes for all letters must be different. For some letters substitute letter may coincide with the original letter. For example, applying substitution cipher that changes all letters from 'A' to 'Y' to the next ones in the alphabet, and changes 'Z' to 'A', to the message "VICTORIOUS" one gets the message "WJDUPSJPVT".

“移位”只是置换密码的一种,只要满足“Substitutes for all letters must be different.”就是置换了,比如

A->B

C->H

Z->D

对于这道题,input:

AAABB
CCCEE

应输出

YES

所以明文与密文的“字母频率的数组”应该是一样的,即明文中某字母出现8次,密文中也必须有某个字母出现8次。

所以字母种类,字母频率同时相等时,即被破解。

permutation cipher(排列密码):

Permutation cipher applies some permutation to the letters of the message. For example, applying the permutation <2, 1, 5, 4, 3, 7, 6, 10, 9, 8> to the message "VICTORIOUS" one gets the message "IVOTCIRSUO".

明文随机排列,所以字母种类和频率都不变。

对于这道题,排列密码考虑和不考虑对解题无影响!


#include<stdio.h>


#include<string.h>


#define MAX 101


char a[2][MAX];


int main()


{


int i, j, l;


int n[2][26]={0};


scanf("%s", a);


scanf("%s", a+1);


l = strlen(a[0]);


for(i=0; i<l; i++)


{


n[0][a[0][i]-'A']++;


n[1][a[1][i]-'A']++;


}


for(i=0; i<26; i++)


{


for(j=0; j<26; j++)


if(n[0][i] == n[1][j])


{


n[1][j] = 0;


break;


}


if(j == 26)


{


printf("NO/n");


break;


}


}


if(i == 26)


printf("YES/n");


return 0;


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: