本文主要是介绍Caesar Cipher,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
In cryptography, a Caesar cipher, also known as the shift cipher, is one of the most straightforward and most widely known encryption techniques.It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions up (or down) the alphabet.
For example, with the right shift of 1919, A
would be replaced by T
, B
would be replaced by U
, and so on.A full exhaustive list is as follows:
Now you have a plaintext and its ciphertext encrypted by a Caesar Cipher.You also have another ciphertext encrypted by the same method and are asked to decrypt it.
Input Format
The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 5050.
For each test case, the first line contains two integers nn and m~(1 \le n,m \le 50)m (1≤n,m≤50) indicating the length of the first two texts (a plaintext and its ciphertext) and the length of the third text which will be given.Each of the second line and the third line contains a string only with capital letters of length nn, indicating a given plaintext and its ciphertext respectively.The fourth line gives another ciphertext only with capital letters of length mm.
We guarantee that the pair of given plaintext (in the second line) and ciphertext (in the third line) is unambiguous with a certain Caesar Cipher.
Output Format
For each test case, output a line containing Case #x: T
, where xx is the test case number starting from 11, and TT is the plaintext of the ciphertext given in the fourth line.
样例输入
1
7 7
ACMICPC
CEOKERE
PKPIZKC
样例输出
Case #1: NINGXIA
分析:
签到题,没什么好分析的啦根据给出的两列,计算出之间的关系
代码:
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
char s1[55],s2[55],s[55];
int n,m;
int main()
{
int k,casee=0,i,a;
char b;
scanf("%d",&k);
while(k--)
{
scanf("%d %d",&n,&m);
scanf("%s",s1);
scanf("%s",s2);
a=s2[0]-s1[0];
scanf("%s",s);
printf("Case #%d: ",++casee);
for(i=0;i<m;i++)
{
b=s[i]-a;
if(b-'A'<=0)
b=b+26;
if(b-'Z'>0)
b=b-26;
printf("%c",b);
}
printf("\n");
}
return 0;
}
这篇关于Caesar Cipher的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!