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 TB 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;
}
 

發佈了120 篇原創文章 · 獲贊 27 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章