CF——Caesar Cipher

博客介绍了Caesar Cipher(凯撒密码),它是一种简单且广泛使用的加密技术,通过将明文中的字母按字母表固定位置替换。给出了输入输出格式及示例,要求根据已知的明文和密文对,解密另一个密文。

C. Caesar Cipher
time limit per test10.0 s
memory limit per test256 MB
inputstandard input
outputstandard output
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 19, A would be replaced by T, B would be replaced by U, and so on. A full exhaustive list is as follows:

The plaintext: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z;
The ciphertext: T U V W X Y Z A B C D E F G H I J K L M N O P Q R S.
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
The input contains several test cases, and the first line is a positive integer T indicating the number of test cases which is up to 50.

For each test case, the first line contains two integers n and 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 n, indicating a given plaintext and its ciphertext respectively. The fourth line gives another ciphertext only with capital letters of length m.

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
For each test case, output a line containing Case #x: T, where x is the test case number starting from 1, and T is the plaintext of the ciphertext given in the fourth line.

Example
input
1
7 7
ACMICPC
CEOKERE
PKPIZKC
output
Case #1: NINGXIA

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    int case1=0;
    cin>>t;
    while(t--)
    {
        case1++;
        int m,n;
        cin>>n>>m;
        char a[55],b[55],c[55];
        scanf("%s%s",a,b);
        int r=b[0]-a[0];//记录相差距离
        scanf("%s",c);
        cout<<"Case #"<<case1<<": ";
        for(int i=0;i<m;i++) 
        {
            if(c[i]-r>'Z')//分情况>Z,<A,A<=' '<=Z
            printf("%c",c[i]-r-26);
            else if(c[i]-r<'A')
            printf("%c",c[i]-r+26);
            else
            printf("%c",c[i]-r);
        }
        cout<<endl;
    }
    return 0;
 } 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值