Problem D"Decoding Task"

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100002

Description

In the near future any research and publications about cryptography are outlawed throughout the world on the grounds of national security concerns. The reasoning for this is clear and widely accepted by all governments - if cryptography literature is public like in the old times, then everybody (even criminals and terrorists) could easily use it to hide their malicious plans from the national and international security forces. Consequently, public cryptographic algorithms and systems have ceased to exist, and everybody who needs strong protection for their secrets is forced to invent proprietary algorithms.

The ACM Corporation has lots of competitors who are eager to learn its trade secrets. Moreover, the job to protect their secrets is complicated by the fact, that they are forced to use intercontinental communication lines which are easy to eavesdrop on, unlike internal lines of the ACM Corporation which are well guarded. Therefore, the ACM Corporation have invented the Intercontinental Cryptographic Protection Code (ICPC) which they are very proud of, and which is considered unbreakable - nobody has even tried to break it yet, but that is about to change.

The group of hackers was hired by the rival company, which does not disclose its name to them, to break ICPC. As the first step, they have bribed one of the programmers who implemented the software for ICPC and have learned how ICPC works. It turns out, the ICPC uses very long key which is a sequence of bytes generated by some sophisticated and random physical process. This key is changed weekly and is used to encrypt all messages that are sent over intercontinental communication lines during the week. This programmer has also proudly told them, that ICPC is the fastest code in the world, because (having the benefit of highly sophisticated code generation) they simply perform bitwise exclusive OR (XOR) operation between the bytes of the message and the key. That is, the ith byte of the encrypted message Ei = Ki XOR Ci, where Ki is the ith byte of the key and Ci is the ith byte of the original clear-text message.

Having learned how ICPC works, they have started to look for the way to reliably obtain the key every week, which is the only thing that is still missing to listen for all intercontinental communications of the ACM Corporation (eavesdropping on the intercontinental lines themselves has indeed turned out to be an easy task). An attempt to bribe the security officers who guard and distribute the key has failed, because the security officers (having the profession with one the highest salaries of that time) have turned out to be too expensive to bribe.

During the search for alternative solutions, they have stumbled upon a clerk, who sends weekly newsletters to various employees and departments. Fortunately, these newsletters are being sent just after the change of the key and the messages are usually long enough to recover sufficient portions of the key by studying original newsletters and their encoded forms. However, they could not covertly find anyone who will disclose the newsletter contents on a weekly basis, because all the employees were bound by a Non-Disclosure Agreement (NDA) and the penalty for the disclosure of any corporate message according to this NDA is death.

Yet they were able to convince this clerk (for a small reward) to do a seemingly innocent thing. That is, while sending the copies of newsletter throughout the corporation, he was instructed to insert an extra space character in the beginning of some messages but send other copies in their original form. Now the task to recover the key is straightforward and it is you, who shall create a program for this. The program is given two ICPCed messages where the first message is N bytes, and the second one is N+1 bytes and is the result of encoding the same clear-text messages as the first one, but with one extra space character (represented by the byte with the decimal value of 32) in the beginning. The program shall find the first N+1 bytes of the key that was used to encode the messages.

Input

The input file consists of two lines. The first line consists of 2N characters and represents the encoded message N bytes long. The second line consists of 2N+2 characters and represents the encoded message N+1 bytes long. Here 1 ≤ N ≤ 10000. Each message is written on a single line in a hexadecimal form byte by byte without spaces. Each byte of the message is represented by two characters '0'-'9', 'A'-'F' that represent the hexadecimal value of the corresponding byte.

Output

Write to the output file a single line that represents N+1 bytes of the recovered key in the same hexadecimal format as in the input file.

Sample Input

05262C5269143F314C2A69651A264B

610728413B63072C52222169720B425E

Sample Output

41434D2049435043204E454552432732

HINT

 

题意

给你一个密码条,A按位异或B之后可以得到C1

现在在A的前面加了一个空格,得到了C2

然后给你C2和C1,让你求B

题解:

画画就知道每次都可以得到一个方程AxorB=C,我们知道其中两个数,很容易推出第三个数

每次都这个搞一搞就好了……

空格和C可以得到第一个B,然后一直算下去就好了

代码:

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <vector>
  7. #include <stack>
  8. #include <map>
  9. #include <set>
  10. #include <queue>
  11. #include <iomanip>
  12. #include <string>
  13. #include <ctime>
  14. #include <list>
  15. #include <bitset>
  16. typedef unsigned char byte;
  17. #define pb push_back
  18. #define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
  19. #define local freopen("in.txt","r",stdin)
  20. #define pi acos(-1)
  21.  
  22. using namespace std;
  23. const int maxn = 3e4 + ;
  24. char s1[maxn] , s2[maxn];
  25. int l1,l2;
  26. vector<int>T1,T2;
  27. char ans[maxn];
  28.  
  29. inline int GetLetter(char x)
  30. {
  31. if(x <= '' && x >= '') return x - '';
  32. else return x-'A'+;
  33. }
  34.  
  35. char A(int x)
  36. {
  37. if(x<=&&x>=) return x + '';
  38. else return x - +'A';
  39. }
  40.  
  41. void output(int x)
  42. {
  43. int y2 = x % ;
  44. int y1 = (x- y2)/;
  45. printf("%c%c",A(y1),A(y2));
  46. }
  47.  
  48. void solve()
  49. {
  50. for(int i = ; i < l1 ; i += )
  51. {
  52. int v1 = GetLetter(s1[i]) , v2 = GetLetter(s1[i+]);
  53. T1.push_back(v1* + v2);
  54. }
  55. for(int i = ; i < l2 ; i += )
  56. {
  57. int v1 = GetLetter(s2[i]) , v2 = GetLetter(s2[i+]);
  58. T2.push_back(v1* + v2);
  59. }
  60. int pre = () ^ T2[];
  61. output(pre);
  62. for(int i = ; i < T1.size() ; ++ i)
  63. {
  64. int xx = pre ^ T1[i];
  65. pre = T2[i+] ^ xx;
  66. output(pre);
  67. }
  68. printf("\n");
  69. }
  70.  
  71. int main(int argc,char *argv[])
  72. {
  73. freopen("decode.in","r",stdin);
  74. freopen("decode.out","w",stdout);
  75. scanf("%s%s",s1,s2);
  76. l1 = strlen(s1); l2 = strlen(s2);
  77. solve();
  78. return ;
  79. }

Codeforces Gym 100002 D"Decoding Task" 数学的更多相关文章

  1. Codeforces Gym 100002 E "Evacuation Plan" 费用流

    "Evacuation Plan" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  2. Codeforces Gym 100002 C "Cricket Field" 暴力

    "Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...

  3. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  4. Codeforces Gym 100002 B Bricks 枚举角度

    Problem B Bricks" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 ...

  5. Codeforces Gym 100425A Luggage Distribution 二分 数学

    A - Luggage DistributionTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...

  6. Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task 数学 mod运算的性质

    C. Ehab and a 2-operation task 数学 mod运算的性质 题意: 有两种对前缀的运算 1.对前缀每一个\(a +x\) 2.对前缀每一个\(a\mod(x)\) 其中x任选 ...

  7. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  8. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  9. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

随机推荐

  1. ejabberd、jabber、jabberd、xmpp辨析

    Jabber 是著名的即时通讯服务服务器,它是一个自由开源软件,能让用户自己架即时通讯服务器,可以在Internet上应用,也可以在局域网中应用.    XMPP(可扩展消息处理现场协议)是基于可扩展 ...

  2. 实时通讯库 libre/librem/restund/baresip

    http://www.creytiv.com/ 源码下载 libre Toolkit library for asynchronous network IO with protocol stacks ...

  3. [Papers]NSE, $u_3$, Lebesgue space [NNP, QM, 2002; Zhou, JMPA, 2005]

    $$\bex u_3\in L^p(0,T;L^q(\bbR^3)),\quad \frac{2}{p}+\frac{3}{q}=\frac{1}{2},\quad 6< q\leq \inft ...

  4. 仿it快播顶部button点击背景滑动切换的效果

    最近在it快播中看见它顶部的几个button可以点击后 背景会滑动到相应的button后面 就得很好看 就想办法实现了那效果 思路 大概就是通过view的叠加 把3个button通过RelativeL ...

  5. 软件测试技术(三)——使用因果图法进行的UI测试

    目标程序 较上次增加两个相同的输入框 使用方法介绍 因果图法 在Introduction to Software Testing by Paul一书中,将软件测试的覆盖标准划分为四类,logical ...

  6. bzoj 1576 [Usaco2009 Jan]安全路经Travel(树链剖分,线段树)

    [题意] 给定一个无向图,找到1-i所有的次短路经,要求与最短路径的最后一条边不重叠. [思路] 首先用dijkstra算法构造以1为根的最短路树. 将一条无向边看作两条有向边,考察一条不在最短路树上 ...

  7. How do I use SOCKS proxy in delphi?

    TCP====== For Indy 8.0 In Delphi, do the following: IdTCPClient1.SocksInfo.Host := [the DNS name of ...

  8. 设计模式系列 1——StaticFactory(静态工厂),AbstractFactory(抽象工厂)

    本文出自 代码大湿 代码大湿 本系列持续更新,敬请关注. 1 静态工厂 静态工厂介绍: 静态工厂模式可以实现接口封装隔离的原则.在客户端只知接口而不知实现的时候可以使用静态工厂模式. 源码请点击我 角 ...

  9. [置顶] Kendo UI开发教程: Kendo UI 示例及总结

    前面基本介绍完Kendo UI开发的基本概念和开发步骤,Kendo UI的示例网站为http://demos.kendoui.com/ ,包含了三个部分 Web DemoMobile DemoData ...

  10. The h.264 Sequence Parameter Set

    转债:  http://www.cardinalpeak.com/blog/the-h-264-sequence-parameter-set/ View from the Peak The h.264 ...