22738_VigenereCipherAnalysis

2022-5-16 18:22| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506910714400-Problem List-采集的数据-后羿采集器.html

Pro.ID

22738

Title

Vigenere Cipher Analysis

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22738

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 6000/6000 MS (Java/Others)     Memory Limit: 131072/65536 K (Java/Others)
  • 描述

    In this problem set, there is another problem (vigenere) asking you to implement the Vigenere Cipher encryption algorithm. This time, we will demonstrate one of the caveats of that cipher.

    A secret organization Amateur Codebreakers Movement has a strong suspicion that bank robbers are planning another strike soon. Unfortunately, we do not know neither the name of the bank nor the exact day and time. ACM is able to eavesdrop the communication between robbers and their driver but the communication is encrypted using the Vigenere Cipher.

    Your task is to try to break the cipher. You are given two words that are likely to appear in the original plaintext — so-called cribs (such words played an important role, for example, in breaking the famous Enigma code).

    输入

    (For the specification of the Vigenere cipher, please refer to the vigenere problem.)

    The input contains several instances. Each instance consists of four lines — the first line is an integer number K, 1 ≤ K ≤ 100, the maximum length of the encryption key to be considered. The second and third lines contain the cribs W1 and W2, 1 ≤ Klength(Wi) ≤ 100. The fourth line is the ciphertext C, 1 ≤ length(C) ≤ 100000. Both the cribs W1, W2 and the ciphertext C consist only of uppercase letters of the standard English alphabet {A, B, C, ..., Z}. The input is terminated by a line containing one zero.

    输出

    Description

    In this problem set, there is another problem (vigenere) asking you to implement the Vigenere Cipher encryption algorithm. This time, we will demonstrate one of the caveats of that cipher.

    A secret organization Amateur Codebreakers Movement has a strong suspicion that bank robbers are planning another strike soon. Unfortunately, we do not know neither the name of the bank nor the exact day and time. ACM is able to eavesdrop the communication between robbers and their driver but the communication is encrypted using the Vigenere Cipher.

    Your task is to try to break the cipher. You are given two words that are likely to appear in the original plaintext — so-called cribs (such words played an important role, for example, in breaking the famous Enigma code).

    Input

    (For the specification of the Vigenere cipher, please refer to the vigenere problem.)

    The input contains several instances. Each instance consists of four lines — the first line is an integer number K, 1 ≤ K ≤ 100, the maximum length of the encryption key to be considered. The second and third lines contain the cribs W1 and W2, 1 ≤ Klength(Wi) ≤ 100. The fourth line is the ciphertext C, 1 ≤ length(C) ≤ 100000. Both the cribs W1, W2 and the ciphertext C consist only of uppercase letters of the standard English alphabet {A, B, C, ..., Z}. The input is terminated by a line containing one zero.

    Output

    Your program must determine how many different plaintexts there exist that contain both of the given cribs simultaneously inside the same message and that will result into the given ciphertext using the Vigenere Cipher with some key Q, 1 ≤ length(Q) ≤ K.

    Print one line for each input instance:

    • If there is exactly one plaintext satisfying all conditions, output that plaintext with no additional spaces.

    • If two or more such plaintexts exist, print the word "ambiguous".

    • If there is no such plaintext, print "impossible".

    Sample Input

    4
    BANK
    MONEY
    FTAGUAVMKILCKPRIJCHRJZIYUAXFNBSLNNXMVDVPXLERWDS
    5
    SECOND
    PARSEC
    SUKCTZHYYES
    3
    ACM
    IBM
    JDNCOFBEN
    4
    ABCD
    EFGH
    OPQRHKLMN
    0

    Sample Output

    WEWILLROBTHEBANKANDTAKEALLTHEMONEYTOMORROWATNOON
    impossible
    ambiguous
    EFGHXABCD

    Source

    样例输入

    4
    BANK
    MONEY
    FTAGUAVMKILCKPRIJCHRJZIYUAXFNBSLNNXMVDVPXLERWDS
    5
    SECOND
    PARSEC
    SUKCTZHYYES
    3
    ACM
    IBM
    JDNCOFBEN
    4
    ABCD
    EFGH
    OPQRHKLMN
    0

    样例输出

    WEWILLROBTHEBANKANDTAKEALLTHEMONEYTOMORROWATNOON
    impossible
    ambiguous
    EFGHXABCD

    提示

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部