POJ - 1107 W's Cipher

Time Limit: 1000MS

Memory Limit: 10000KB

64bit IO Format: %I64d & %I64u

Description

Weird Wally's Wireless Widgets, Inc. manufactures an eclectic assortment of small, wireless, network capable devices, ranging from dog collars, to pencils, to fishing bobbers. All these devices have very small memories. Encryption algorithms like Rijndael, the candidate for the Advanced Encryption Standard (AES) are demonstrably secure but they don't fit in such a tiny memory. In order to provide some security for transmissions to and from the devices, WWWW uses the following algorithm, which you are to implement.

Encrypting a message requires three integer keys, k1, k2, and k3. The letters [a-i] form one group, [j-r] a second group, and everything else ([s-z] and underscore) the third group. Within each group the letters are rotated left by ki positions in the message. Each group is rotated independently of the other two. Decrypting the message means doing a right rotation by ki positions within each group.

Consider the message the_quick_brown_fox encrypted with ki values of 2, 3 and 1. The encrypted string is _icuo_bfnwhoq_kxert. The figure below shows the decrypting right rotations for one character in each of the three character groups.

Looking at all the letters in the group [a-i] we see {i,c,b,f,h,e} appear at positions {2,3,7,8,11,17} within the encrypted message. After a right rotation of k1=2, these positions contain the letters {h,e,i,c,b,f}. The table below shows the intermediate strings that come from doing all the rotations in the first group, then all rotations in the second group, then all the rotations in the third group. Rotating letters in one group will not change any letters in any of the other groups.

All input strings contain only lowercase letters and underscores(_). Each string will be at most 80 characters long. The ki are all positive integers in the range 1-100.

Input

Input consists of information for one or more encrypted messages. Each problem begins with one line containing k1, k2, and k3 followed by a line containing the encrypted message. The end of the input is signalled by a line with all key values of 0.

Output

For each encrypted message, the output is a single line containing the decrypted string.

Sample Input

2 3 1

_icuo_bfnwhoq_kxert

1 1 1

bcalmkyzx

3 7 4

wcb_mxfep_dorul_eov_qtkrhe_ozany_dgtoh_u_eji

2 4 3

cjvdksaltbmu

0 0 0

Sample Output

the_quick_brown_fox

abcklmxyz

the_quick_brown_fox_jumped_over_the_lazy_dog

ajsbktcludmv

Source

Mid-Central USA 2001

 #include<stdio.h>
#include<string.h>
char str[] = {};
char str1[] = {};
char str2[] = {};
char str3[] = {}; int main()
{
int a, b, c, len, alen, blen, clen;
while(scanf("%d%d%d", &a, &b, &c)) {
if(a == && b == && c == ) {
break;
}
scanf("%s", str);
len = strlen(str);
alen = blen = clen = ;
for(int i = ; i < len; i++) {
if(str[i] >= 'a' && str[i] <= 'i') {
str1[alen] = str[i];
alen++;
}
else if(str[i] >= 'j' && str[i] <= 'r') {
str2[blen] = str[i];
blen++;
}
else {
str3[clen] = str[i];
clen++;
}
}
// puts(str1);
// puts(str2);
// puts(str3); if(alen != ) a = a % alen;//这一步是关键
if(blen != ) b = b % blen;//这一步是关键
if(clen != ) c = c % clen;//这一步是关键
int t1 = , t2 = , t3 = ;
for(int i = ; i < len; i++) {
if(str[i] >= 'a' && str[i] <= 'i') {
printf("%c", str1[(t1-a+alen)%alen]);
t1++;
}
else if(str[i] >= 'j' && str[i] <= 'r') {
printf("%c", str2[(t2-b+blen)%blen]);
t2++;
}
else {
printf("%c", str3[(t3-c+clen)%clen]);
t3++;
}
}
printf("\n");
} return ;
}

POJ - 1107 W's Cipher的更多相关文章

  1. poj 2159 D - Ancient Cipher 文件加密

    Ancient Cipher Description Ancient Roman empire had a strong government system with various departme ...

  2. ZOJ 1042 W’s Cipher

    原题链接 题目大意:按照规则解码.26个字母分成三组,每一组按照顺时针移位编码.现在已知移动的位数,要求解码. 解法:以前看过一本古典密码学的书,百度贴吧密码吧也有很多经典的加密方法,想什么凯撒移位. ...

  3. POJ 1107

    水题一道,注意取模时不能为0 #include <iostream> #include <algorithm> #include <cstring> #includ ...

  4. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  5. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  6. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  7. PHP的AES加密类

    PHP的AES加密类 aes.php <?php /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ...

  8. ethereumjs/ethereumjs-wallet

    Utilities for handling Ethereum keys ethereumjs-wallet A lightweight wallet implementation. At the m ...

  9. SSIS 学习之旅 FTP文件传输-脚本任务

    这一章主要讲解一下用脚本怎么把CSV文件抛送到FTP服务器上 设计:   通过Demon库的Users表数据生成CSV文件.   生成后的CSV文件抛送到FTP指定目录下. 控件的使用这里就不做详细讲 ...

随机推荐

  1. DBLink创建 ORA-12154: TNS: 无法解析指定的连接标识符

    因为对oracle不了解,这个问题可TM的搞了好久! 走的弯路: 1. 在客服端的PLSQL连接工具上折腾,而不是在服务器的PLSQL解决 2. 配置的tnsnames.org文件在环境变量path( ...

  2. CSS的class、id、css文件名的常用命名规则

    CSS的class.id.css文件名的常用命名规则        (一)常用的CSS命名规则 头:header       内容:content/container       尾:footer   ...

  3. Js中找任意对象的原型方法及改造原型

    Java中有运行时类型识别,js可以很方便的模仿这个特性,因为所有js对象都有一个属性constructor(构造器),表示这个对象的构造方法,原型与构造方法同名,所以可以通过这儿知道任意对象的原型名 ...

  4. svn学习笔记(1)入门学习----安装及创建运行仓库

    学习及使用svn有一段时间了,但是以前学习的时候不怎么用,现在用只是简单的更新上传,又把基本理论忘了.为了以后自己看自己的笔记回忆,特此记录 svn学习博客:http://www.cnblogs.co ...

  5. 帝国备份王(Empirebak)万能cookie及拿shell

    1.伪造cookie登录系统(其实这一步多余的,大多用户连密码都没改,都是默认的123456) 登录成功设置4个cookie,看代码 function login($lusername,$lpassw ...

  6. JSTL 核心标签库 使用(C标签)

    JSTL 核心标签库标签共有13个,功能上分为4类: 1.表达式控制标签:out.set.remove.catch 2.流程控制标签:if.choose.when.otherwise 3.循环标签:f ...

  7. 2_STL容器

    STL算法的精髓在于  算法的  返回值!!! String: string是STL的字符串类型,通常用来表示字符串:C语言中一般用char* char*字符指针;string是类封装了char*,管 ...

  8. 关于struts2上传图片临时文件

  9. 杭电ACM 1197

    #include<stdio.h>main(){ int temp,i,t,sum10,sum12,sum16; for(i=1000;i<=9999;i++) { temp=i; ...

  10. 【iCore3 双核心板】例程十一:DMA实验——存储器到存储器的传输

    实验指导书及代码包下载: http://pan.baidu.com/s/1bcY5JK iCore3 购买链接: https://item.taobao.com/item.htm?id=5242294 ...