中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 未整理篇
acm.jlu.edu.cn-1068-Cipher
作者:macox 时间:2003-02-20 11:10 出处:互联网 责编:chinaitpower
              摘要:acm.jlu.edu.cn-1068-Cipher

Bob and Alice started to use a brand-new encoding scheme. Surprisingly it is not a Public Key Cryptosystem, but their encoding and decoding is based on secret keys. They chose the secret key at their last meeting in Philadelphia on February 16th, 1996. They chose as a secret key a sequence of n distinct integers, a1 ; . . .; an, greater than zero and less or equal to n. The encoding is based on the following principle. The message is written down below the key, so that characters in the message and numbers in the key are correspondingly aligned. Character in the message at the position i is written in the encoded message at the position ai, where ai is the corresponding number in the key. And then the encoded message is encoded in the same way. This process is repeated k times. After kth encoding they exchange their message.

The length of the message is always less or equal than n. If the message is shorter than n, then spaces are added to the end of the message to get the message with the length n.

Help Alice and Bob and write program which reads the key and then a sequence of pairs consisting of k and message to be encoded k times and produces a list of encoded messages.

Input

The input file consists of several blocks. Each block has a number 0 < n <= 200 in the first line. The next line contains a sequence of n numbers pairwise distinct and each greater than zero and less or equal than n. Next lines contain integer number k and one message of ascii characters separated by one space. The lines are ended with eol, this eol does not belong to the message. The block ends with the separate line with the number 0. After the last block there is in separate line the number 0.

Output

Output is divided into blocks corresponding to the input blocks. Each block contains the encoded input messages in the same order as in input file. Each encoded message in the output file has the lenght n. After each block there is one empty line.

Sample Input

10
4 5 3 7 2 8 1 6 10 9
1 Hello Bob
1995 CERC
0
0

Sample Output

BolHeol  b
C RCE


 






#include<iostream> #include<string> #include<memory> using namespace std; const int N=201; void main() { int key[N]; //secret kay int keys[N]; //group information char ct[N]; //CipherText bool used[N]; int cycle[N][N]; int n; while(cin>>n,n>0) { for(int i=0;i<n;i++) { cin>>key[i]; } memset(used,0,n*sizeof(bool)); int x=0; int idxc=0; while(x<n) { if(used[x]) { x++; continue; } else { used[x]=true; int mark=x; int len=1; cycle[idxc][len]=key[x]; while(key[x]!=mark+1) { len++; x=key[x]-1; used[x]=true; cycle[idxc][len]=key[x]; } cycle[idxc][0]=len; for(int i=1;i<=len;i++) { keys[cycle[idxc][i]-1]=idxc; } x=mark; idxc++; } x++; } int m; while(cin>>m,m>0) { char ch; cin.get(ch); int idx=0; while(cin.get(ch),ch!='\n') { ct[idx++]=ch; } for(int i=idx;i<n;i++) ct[i]=' '; char it[N];//intertext; memset(used,0,n*sizeof(bool)); x=0; while(x<n) { if(used[x]) { x++; continue; } int mark=keys[x]; int step=m%cycle[mark][0]; int pi=1,pj=pi+step; for(int i=0;i<cycle[mark][0];i++) { used[cycle[mark][pj]-1]=true; it[cycle[mark][pj]-1]=ct[cycle[mark][pi]-1]; pi++;pj++; if(pj==cycle[mark][0]+1) pj=1; } x++; } it[n]='\0'; cout<<it<<endl; } cout<<endl; } }

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有