1236. Decoding Task
https://acm.timus.ru/problem.aspx?space=1&num=1236
思路
- 对于带空格串加密结果,第一个字符61,K1K2 XOR 32 = 61,可以算出K1K2
- 对于原始串加密结果,第一个字符05, K1K2 XOR C1C2 = 05, 可以算出C1C2
- 对于带空格串加密结果,第二个字符07, K3K4 XOR C1C2 = 07, 可以算出 K3K4
- 对于原始串加密结果,第二个字符26, K3K4 XOR C3C4 = 26, 可以算出C3C4
- 对于带空格串加密结果,第三个字符28, K5K6 XOR C3C4 = 28, 可以算出 K3K4
- ...
- ...
- ...
Code
https://blog.csdn.net/qq_38231051/article/details/82392330
#include <stdio.h> #include <stdlib.h> #include <string.h> char a[20004]; char b[20004]; char c[20004]; int ten(int i,char* x) { int k; if(x[2*i]>='A'){ k = (10+x[2*i]-'A')*16; }else k = (x[2*i]-'0')*16; if(x[2*i+1]>='A'){ k += (10+x[2*i+1]-'A'); }else k += (x[2*i+1]-'0'); return k; } void setnum(int first,int end,int i) { if(first>=10){ c[2*i] = 'A'+first-10; }else c[2*i] = '0'+first; if(end>=10){ c[2*i+1] = 'A'+end-10; } else c[2*i+1] = '0'+end; } void getit(int len) { int first,end; int i=0,j=0; int temp=32; int result; int A=0; A = ten(0,b); result = A^temp; first = result/16; end = result%16; setnum(first,end,i); ++i; int k=0; for(k=0;k<len/2;++k) { temp = result^ten(k,a); A = ten(k+1,b); result = A^temp; first = result/16; end = result%16; setnum(first,end,k+1); ++i; } c[(k+1)*2]='\0'; } int main() { int temp,len; while(scanf("%s %s",a,b)!=EOF){ getit(strlen(a)); printf("%s\n",c); } }
https://blog.csdn.net/worldvagrant/article/details/108608292
标签:10,1236,Task,end,int,Decoding,XOR,加密,first From: https://www.cnblogs.com/lightsong/p/16971577.html