Training: Encodings I (Training, Encoding)

We intercepted this message from one challenger to another, maybe you can find out what they were talking about.
To help you on your progress I coded a small java application, called JPK.
Note: The message is most likely in english.
 

10101001101000110100111100110100
00011101001100101111100011101000
10000011010011110011010000001101
11010110111000101101001111010001
00000110010111011101100011110111
11100100110010111001000100000110
00011110011110001111010011101001
01011100100000101100111011111110
10111100100100000111000011000011
11001111100111110111110111111100
10110010001000001101001111001101
00000110010111000011110011111100
11110011111010011000011110010111
0100110010111100100101110
#include<stdio.h>
#include<string.h>
//下面的字符串总共有714个字符。
char strs[714]= "0,NUL,16,DLE,32, ,48,0,64,@,80,P,96,`,112,p,1,SOH,17,DC1,33,!,49,1,65,A,81,Q,97,a,113,q,2,STX,18,DC2,34,\",50,2,66,B,82,R,98,b,114,r,3,ETX,19,DC3,35,#,51,3,67,C,83,S,99,c,115,s,4,EOT,20,DC4,36,$,52,4,68,D,84,T,100,d,116,t,5,ENQ,21,NAK,37,%,53,5,69,E,85,U,101,e,117,u,6,ACK,22,SYN,38,&,54,6,70,F,86,V,102,f,118,v,7,BEL,23,ETB,39,',55,7,71,G,87,W,103,g,119,w,8,BS,24,CAN,40,(,56,8,72,H,88,X,104,h,120,x,9,HT,25,EM,41,),57,9,73,I,89,Y,105,i,121,y,10,LF,26,SUB,42,*,58,:,74,J,90,Z,106,j,122,z,11,VT,27,ESC,43,+,59,;,75,K,91,[,107,k,123,{,12,FF,28,FS,44,,,60,<,76,L,92,\\,108,l,124,|,13,CR,29,GS,45,-,61,=,77,M,93,],109,m,125,},14,SO,30,RS,46,.,62,>,78,N,94,^,110,n,126,~,15,SI,31,US,47,/,63,?,79,O,95,_,111,o,127,DEL,";
char words[128][5];//共有128个ascii码字符
int bin_to_int(char *chs){//chs的长度为7
	int res = 0;
	for(int i = 0;i < 7;i++)
	{
		res = res * 2 + (chs[i] - '0');
	}
	return res;
}
int bin_to_int_2(char *chs,int len)//chs的长度小于7
{
	int res = 0;
	for(int i = 0;i < len;i++)
	{
		res = res * 2 + (chs[i] - '0');
	}
	return res;
}

void initial(){
	int len = strlen(strs);
	//printf("len=%d\n",len);
	int i = 0;
	int j = 0;
	int result = 0;
	memset(words,0,sizeof(words));
	while(i < len) //strs的长度(字符的个数)
	{
		result = 0;
		while(strs[i] != ',' && i < len)
		{
			result = result * 10 + (strs[i++] - '0');//计算对应的ascii十进制数值
		}
		i++;
		j = 0;
		while(strs[i] != ',' || i == 548) //逗号","本身作为分隔符存在,但是逗号本身也是一个ascii符号,这里需要做一下特殊处理,逗号对应的字符在strs中的下标是548
		{
			words[result][j++] = strs[i++];
		}
		//printf("%d\n%s\n----------------\n",result,words[result]);
		i++;
	}
}
void mydo(){
	char chs[1000] = {0};
	//memset(chs,0,sizeof(chs));
	scanf("%s",chs);
	//printf("输入成功!");
	//printf("%s\n",chs);
	int len = strlen(chs);
	int res_len = len;
	int i = 0;
	while(len){
		if(res_len >= 7)
		{
			int res = bin_to_int(chs + i);
			printf("%s",words[res]);
			i += 7;
			res_len -= 7;
		}
		else
		{
			int res = bin_to_int_2(chs + i,res_len);
			printf("%s",words[res]);
		}
		len -= 7;
	}
}
int main(){
	initial();
	mydo();
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值