UVALive 5880 Vigenère Cipher Encryption (模拟)

本文介绍了一个简单的字符串加密算法实现过程,通过使用密钥对输入的明文进行加密处理,最终输出密文。文章提供了一段C++代码示例,演示如何进行字符串的加密。

Stack Machine Executor

题目链接:

http://acm.hust.edu.cn/vjudge/problem/26628

Description


http://7xjob4.com1.z0.glb.clouddn.com/18113a5cf78f108997460e36f7079fc6

Input


The input contains several instances. Each instance consists of two lines, the first line is the encryption
key and the second line is the plaintext. Both key and plaintext consist of uppercase letters of the
English alphabet {A, B, C, . . . , Z}. The length of the key will be between 1 and 1000, the length of the
plaintext between 1 and 100 000, inclusive.
Input is terminated by a line containing one zero.

Output


For each input instance, output the ciphertext — the encrypted version of the message.

Sample Input


ICPC
THISISSECRETMESSAGE
ACM
CENTRALEUROPEPROGRAMMINGCONTEST
LONGKEY
CERC
0

Sample Output


CKYVRVIHLUUWVHIVJJU
DHAUUNMHHSRCFSEPJEBPZJQTDRAUHFU
OTFJ

Source


2016-HUST-线下组队赛-1


题意:


用密钥来加密字符串.


题解:


题目真是长,然而是签到题...
要练习一下快速读题了...不要看到长题面不敢读..
直接模拟即可.


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <list>
#define LL long long
#define eps 1e-8
#define maxn 101000
#define mod 100000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;

char str[maxn];
char key[maxn];

int main(int argc, char const *argv[])
{
    //IN;

    while(gets(key) && key[0] != '0')
    {
        gets(str);

        int klen = strlen(key);
        int len = strlen(str);

        for(int i=0,j=0; i<len; i++,j++) {
            if(j == klen) j = 0;
            str[i] = (str[i] + key[j] - 'A' + 1 - 'A') % 26 + 'A';
        }

        puts(str);
    }

    return 0;
}

转载于:https://www.cnblogs.com/Sunshine-tcf/p/5791209.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值