UVA10896 Known Plaintext Attack【文本】

One of the earliest encrypting systems is attributed to Julius Caesar: if the letter to be encrypted is the m-th letter in the alphabet, replace it with the (m + k)-th where k is some fixed integer. Caesar used k = 3, or a → d, as the key to the encryption. That is, “a” would be encrypted to “d”, “b” would be “e”, and so on until “z” would be “c”. For example, for a → k, the sentence “this is a test” would become “drsc sc k docd”.
    Now you have an encrypted sentence, and you know a decrypted word in that sentence. Your task is to find all the possible keys to the encryption.
Input
The input starts with a line containing a number, n, followed by n sets of encrypted sentence/decrypted word pairs. Each set has two lines, the first line is the encrypted sentence which contains only words separated by a space with no punctuation, the second line contains a word which is one of the decrypted word of the sentence above it. All words are in lowercase letters. You may assume a word is at most 16 characters long, and a line has no more than 70 characters.
Output
The output has n lines of character(s), corresponding to the n sets of encrypted sentence/decrypted word pairs.
    The line consists of lowercase letter(s) of possible key(s). That is, if the plaintext “a” is encrypted to “x”, then ‘x’ would be in the line.
    Each line of characters must be sorted in alphabetical order.
Sample Input
2
drsc sc k docd
test
dl ruvd doha hp pz
we
Sample Output
k
hl

问题链接UVA10896 Known Plaintext Attack
问题简述:(略)
问题分析
    简单的文本处理题,不解释。给出的程序代码是比较简洁的。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10896 Known Plaintext Attack */

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin >> t;
    getchar();
    while(t--) {
        string s, word;
        getline(cin, s);
        getline(cin, word);

        set<char> ans;
        set<int> st;
        int n = s.size(), m = word.size(), j = 0;
        for(int i = 0; i < n; i++) {
            if(islower(s[i])) {
                if(j < m) {
                    st.insert((26 + s[i] - word[j]) % 26);
                    j++;
                }
            } else if(s[i] == ' ') {
                if(j == m) {
                    if(st.size() == 1)
                        ans.insert('a' + (26 + s[i - j] - word[0]) % 26);
                }
                j = 0;
                st.clear();
            }
        }
        if(j == m)
            if(st.size() == 1)
                ans.insert('a' + (26 + s[n - j] - word[0]) % 26);

        for(set<char>::iterator iter = ans.begin(); iter != ans.end(); iter++)
            cout << *iter;
        cout << endl;
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ziperello zip 密码 破解有一种破解方法叫做Known plaintext attack。市面上的密码破解软件几乎都带有这个功能。操作方法就是找到加密压缩包中的任意一个文件,用同样的压缩软件同样的压缩方式压缩成一个不加密的包,然后把这两个压缩包进行比较,这样就能把整个加密的压缩包全部还原成未加密的形式。 原理是这样的:你输入的密码,首先被转换成3个32bit的key,所以可能的key 的组合是2^96,这是个天文数字,如果用暴力穷举的方式是不太可能的,除非你的密码比较短或者有个厉害的字典。压缩软件用这3个key加密所有包中的文件,这也就是说,所有文件的key是一样的,如果我们能够找到这个key,就能解开所有的文件。如果我们找到加密压缩包中的任意一个文件,这个文件和压缩包里的文件是一样的,我们把这个文件用同样的压缩软件同样的压缩方式进行无密码的压缩,得到的文件就是我们的Known plaintext。用这个无密码的压缩包和有密码的压缩包进行比较,分析两个包中相同的那个文件,抽取出两个文件的不同点,就是那3个key了,如此就能得到key。两个相同文件在压缩包中的字节数应该相差12个byte,就是那3个key了。虽然我们还是无法通过这个key还原出密码,但是我们已经可以用这个key解开所有的文件,所以已经满足我的要求了,而且要以前的密码也没什么用呀,我只要文件。 其实很简单,只要你能找到一个相同的文件,就万事大吉了! 所以我用Advanced ZIP Password Recovery(Crack了的)选择Known plaintext attack。用了2分钟就找到了key,然后用了20分钟把我的那个700M的压缩包解开,搞定!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值