WOJ1029-Ascend

Cryptography deals with methods of secret communication that transform a message (the plaintext) into a disguised form (the ciphertext) 

so that no one seeing the ciphertext will be able to figure out the plaintext except the intended recipient. Transforming the plaintext to
the ciphertext is encryption; transforming the ciphertext to the plaintext is decryption.
Ascend is a simple encryption method that only deal with capital letters. It shifts the i-th letter in a word forwards by i steps in alphabet,
and you may assume the alphabet is circular in that letter Z will follow the letter A.
For example: I ascend WHU to XJX. The process is as follow:
1. I shift the first letter W forwards 1 step to X.
2. I shift the second letter H forwards 2 steps to J.
3. I shift the third letter U forwards 3 steps to X.
Your task is to write a program that can decrypt the messages which are ascended.

输入格式

The input file contains one or more test cases, followed by a line containing only the symbol $ that signals the end of the file.
Each test case is on a line by itself and consists of an ascended message containing at least one and at most 100 capital letters.
You may assume the message dose not contain other characters.

输出格式

For each test case, output the decrypted message on a line by itself.

样例输入

XJX
BEPMHVJ
$

样例输出

WHU
ACMICPC

简单的解密题。

#include<stdio.h>
#include<string.h>
int main(){
	char c,s[110],t[110];
	int i,n,ascend;
	while(scanf("%s",&s)&&strcmp(s,"$")){
		n=strlen(s);
		for(i=0;i<n;i++){
			ascend=(i+1)%26;
			c=s[i]-ascend;
			if(c<'A')
			c=s[i]-ascend+'Z'-'A'+1;
			t[i]=c;
		}
		t[i]='\0';
		printf("%s\n",t);
	}
	return 0;
}


全部评论

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 11:33
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务