苏州大学计算机专业2011年复试上机真题(第二题)

题目描述:

文本中内容是一段英文文档(不过是加过密的,打开全是乱码),要求输出密匙cip1和cip2以及解密后的内容。条件:
(1) cip1和cip2都是八位无符号整数;
(2) 加密过程:每次从文本中读出八位字符,然后将该字符和密钥交替异或便是该位置的密文。
如第0个字节与cip1异或,第一个字节和cip2异或,第三个字节和cip1异或,。。。,如此循环至结束。
最后输出cip1和cip2以及完整的英文句子。

输入描述:

柙贉仍瘴販谡墼葴于溝容瘴蠝僖刭販找溳溝任菡墼葴梯舷蒇贉于溝友贉匈役仍愃杖詼仍钨贉赜游蠝商右溔再溞仝葤鯗菅溣讙

输出描述:

cip1为188,cip2为188,解密后内容为:The third fight of stairs ended in a straight passage of some length,with three doors upon the left.I am ok.p

代码:

#include<stdio.h>
#include<stdlib.h>
int isLegal(char a);
void solve(char data[],int i);
int main(){
	FILE *fp;
	char data[2000];
	int i=0;
	int j;
	if((fp=fopen("D:\\2019Post\\pat\\pat\\data2011.txt","rb"))==NULL){
		printf("can not open the file");
		exit(0);
	}
	while(!feof(fp)){
		fread(&data[i],1,1,fp);
		i++;
	}
	solve(data,i);
}

int isLegal(char a){
	if(a>='a'&&a<='z')
		return 1;
	if(a>='A'&&a<='Z')
		return 1;
	if(a==' '||a==','||a=='.')
		return 1;
	return 0;
}

void solve(char data[],int num){
	int i,j,s;
	char temp[2000];
	for(i=0;i<=255;i++)
		for(j=0;j<=255;j++){
			for(s=0;s<num;s++){
				if(s%2==0){
					temp[s]=data[s]^i;
				}else if(s%2==1){
					temp[s]=data[s]^j;
				}
				if(isLegal(temp[s])){
					continue;
				}else
					break;
			}
			if(s==num){
				temp[s]='\0';
				printf("cip1为%d,cip2为%d,解密后内容为:%s",i,j,temp);
			}
		}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值