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;
}
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;
}
相关文章推荐
- POJ-2159-Ancient Cipher-解题报告
- 【原】 POJ 2159 Ancient Cipher 题意万岁 解题报告
- POJ2159解题报告
- poj2159解题报告
- POJ 2159(古代加密) 解题报告
- POJ 2159(古代加密) 解题报告
- POJ 2159 解题报告
- 【原】 POJ 2159 Tree Recovery 解题报告
- POJ2159解题报告
- POJ 2159 解题报告
- POJ 1045 解题报告
- POJ 3006 解题报告
- POJ 1835 宇航员 解题报告
- POJ 2159 Ancient Cipher
- POJ3228 Gold Transportation 解题报告【贪心+并查集=Kruskal?】
- POJ-2965题The Pilots Brothers' refrigerator解题报告
- POJ-3070-Fibonacci 解题报告
- 最小生成树 prim POJ 2349解题报告
- poj 1004 Financial Management 解题报告
- 【转】POJ试题分类 - 实时更新我所有的解题报告链接