编程介的小学生 2017-02-19 05:28 采纳率: 20.5%
浏览 891
已采纳

Cracking the Code

You have been contracted by a terrorist group to crack encrypted transmissions. The only information that the terrorists could give you regarding the encrypted message is that a fixed key-length XOR-encryption algorithm was used to encode it. After a brief search on the 'Net, you find the following definition of XOR-encryption:

Assuming that we have a character u[i] from the unencrypted input stream, and a key k of length l with characters k[j], 0 <= j < l, then the encrypted value e[i] is obtained as follows:

e[i] = u[i] XOR k[i MOD l]

where MOD is the remainder after integer division (the % operator in C, C++ and Java), and XOR is the bitwise XOR operator applied to an 8-bit character (the ^ operator in C, C++ and Java). XOR encryption is a symmetric encryption scheme, so that the message is decoded by encrypting the encrypted message (a second time) with the same key, so that

u[i] = e[i] XOR k[i MOD l]

You are given four encrypted input streams of 30 000 characters each (that is, a continuous input stream of 120 000 characters). Your program must output the four decrypted stream with no other characters embedded. The streams were encrypted using XOR encryption with fixed length keys of fewer than 30 characters. Each character in the key is unique (appears only once), and is selected from the set a..z merged with 0..9.

Your task is to determine the correct key length, and decrypt the encrypted input stream.

Your terrorist friends provided you with one last vital piece of information: ��The decrypted message will be in English.'��

It is recommended that you write an XOR encryption program first to aid you in testing your solution.

SAMPLE INPUT

The output of the XOR encryption algorithm is not normally printable, since it may contain ASCII codes greater than 127. Therefore, the sample-encrypted message below is shown in numerical ASCII values (in decimal) �C the actual input file contains the ASCII symbols.

If the message "the quick brown fox jumps over the lazy dog" is encrypted using the key "12" (the literal characters "1" and "2", concatenated), the following (binary) file results.

69 90 84 18 64 71 88 81 90 18 83 64 94 69 95 18
87 93 73 18 91 71 92 66 66 18 94 68 84 64 17 70
89 87 17 94 80 72 72 18 85 93 86

If these values are converted to ASCII symbols and stored in a file (the file length should be exactly 43 bytes), it can be used as input to your program. It is recommended that you first write the encryption algorithm.

SAMPLE OUTPUT

Your program should determine the key length to be 2 (you should not output this value), and decrypt the message to yield:

the quick brown fox jumps over the lazy dog

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-02-23 15:37
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭