POJ - 1107 W's Cipher
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
#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的更多相关文章
- poj 2159 D - Ancient Cipher 文件加密
Ancient Cipher Description Ancient Roman empire had a strong government system with various departme ...
- ZOJ 1042 W’s Cipher
原题链接 题目大意:按照规则解码.26个字母分成三组,每一组按照顺时针移位编码.现在已知移动的位数,要求解码. 解法:以前看过一本古典密码学的书,百度贴吧密码吧也有很多经典的加密方法,想什么凯撒移位. ...
- POJ 1107
水题一道,注意取模时不能为0 #include <iostream> #include <algorithm> #include <cstring> #includ ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- PHP的AES加密类
PHP的AES加密类 aes.php <?php /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ...
- ethereumjs/ethereumjs-wallet
Utilities for handling Ethereum keys ethereumjs-wallet A lightweight wallet implementation. At the m ...
- SSIS 学习之旅 FTP文件传输-脚本任务
这一章主要讲解一下用脚本怎么把CSV文件抛送到FTP服务器上 设计: 通过Demon库的Users表数据生成CSV文件. 生成后的CSV文件抛送到FTP指定目录下. 控件的使用这里就不做详细讲 ...
随机推荐
- java读取邮件
package com.zz.mail; import java.io.FileNotFoundException; import java.io.FileOutputStream; import j ...
- [CareerCup] 15.6 Entity Relationship Diagram 实体关系图
15.6 Draw an entity-relationship diagram for a database with companies, people, and professionals (p ...
- [zt]Singleton和Double-Checked Locking设计模式—UML图及代码实现
Singleton和Double-Checked Locking设计模式,分别指的是单例模式和双重检查锁模式,它们都可以用于确保某个类只有一个对象实例化. 两个模式的区别在于:Singleton模式用 ...
- div半透明背景,文字不透明
background: rgba(255, 255, 255, 0.8) !important; /* IE无效,FF有效 */ background: #fff; filter: alpha(opa ...
- 关于在VS 上发布网站
在vs 上建立的网站只能用 localhost 进行访问,想要自己本机上的网站发布到IIS上面,这样就可以直接用 IP 地址来访问了,那么照如下的方式做: 1. 首先需要使用vs 发布自己的网站 1. ...
- JAVA6开发WebService (三)——几个概念
转载自http://wuhongyu.iteye.com/blog/808922 要了解WebService,光能写代码不行啊,这说说WebService最基本的概念. 首先WebService要知道 ...
- 手动创建oem
[oracle@std bin]$ /u02/app/product//db_1/bin/emca -config dbcontrol db -repos create STARTED EMCA at ...
- 2016HUAS暑假集训训练2 F - A Simple Problem with Integers
Description 给出了一个序列,你需要处理如下两种询问. "C a b c"表示给[a, b]区间中的值全部增加c (-10000 ≤ c ≤ 10000). " ...
- pt-table-checksum使用实践
在工作中接触最多的就是mysql replication,由于现在公司也还在使用mysql 5.1.x版本,在复制方面还是比较多的问题,比如主库宕机或者从库宕机都会导致复制中断,通常我们需要进行人为修 ...
- Centos上Docker 使用dockerfile构建容器实现ssh
这几日在学习docker.遇到的问题数一年都数不完,网上大多数都是ubuntu的,百度或者谷歌的时候心好累.写写文档来帮助使用centos的docker爱好者们. docker基本操作这里就不介绍了 ...