文章目錄

原题链接http://projecteuler.net/problem=59

XOR decryption

Each character on a computer is assigned a unique code and the preferred standard is ASCII (American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107.

A modern encryption method is to take a text file, convert the bytes to ASCII, then XOR each byte with a given value, taken from a secret key. The advantage with the XOR function is that using the same encryption key on the cipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 = 65.

For unbreakable encryption, the key is the same length as the plain text message, and the key is made up of random bytes. The user would keep the encrypted message and the encryption key in different locations, and without both “halves”, it is impossible to decrypt the message.

Unfortunately, this method is impractical for most users, so the modified method is to use a password as a key. If the password is shorter than the message, which is likely, the key is repeated cyclically throughout the message. The balance for this method is using a sufficiently long password key for security, but short enough to be memorable.

Your task has been made easy, as the encryption key consists of three lower case characters. Using cipher1.txt (right click and ‘Save Link/Target As…’), a file containing the encrypted ASCII codes, and the knowledge that the plain text must contain common English words, decrypt the message and find the sum of the ASCII values in the original text.

异或加密
在计算机中的每个字符都被分配一个唯一的码值,最常用的标准是ASCII(美国标准信息交换码).例如,大写的A = 65,星号(*) = 42,小写的k = 107.

有一种现代的加密方法是将文本文件转化成对应的ASCII,然后将每一个字节与密码中的一个值异或。使用异或方法加密的一个优点是,在密文中使用同样的密钥可以得到明文。例如, 65 XOR 42 = 107 , 之后 107 XOR 42 = 65.

对于不可破解的加密,密钥的长度与明文一样长,并且密钥由随机的字节组成。一个用户将密文和密钥保存在不同的地方,如果没有同时拿到密文和密钥,将不可能破解信息。

不幸的是,这种方法对于许多用户都不实际,因此一个改良的方法是使用密码作为密钥。如果密码的长度小于信息,这也是最常见的情况,那么密钥就要循环贯穿信息。综合考虑,这种方法为了保证安全,选择一个足够长的密钥,为了便于记忆,也必须足够短。

你的任务已经简化了,因为密钥是由三个小写字母构成。使用cipher1.txt(右击,链接另存为),这是一个经过加密的ASCLL码,已经知道的是明文是由英文单词构成,请解密信息,并求原始信息中ASCLL码的总和.

解答:
暴力破解,用常见的英文单词the来判断。

打赏作者

文章目錄