21749_TextEncryption

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

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

Pro.ID

21749

Title

Text Encryption

Title链接

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

AC

27

Submit

109

Ratio

24.77%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    To keep privacy of messages and prevent the aliens from reading them, we may use various encryption algorithms. These algorithms encode a message into the so-called ciphertext that is difficult (or impossible) to decode for anyone else than the intended recipient. Transposition ciphers are a type of encryption that do not change the letters of the message but only change their order ("shuffle" the letters). Of course, the shuffling must be reversible to allow later decryption.

    In this problem, we will consider a simple transposition cipher which shuffles the letters in such a way that the decryption algorithm always takes every n-th letter. More specifically: when decrypting, the first letter of the ciphertext is taken first, then the next n-1 letters are (repeatedly) skipped and the next letter taken, and so on until we reach the end of the ciphertext. After that, we repeat the procedure starting with the second letter of the ciphertext, and so on until all letters are used.

    Your task is to implement the encryption algorithm for this cipher. For a given message, produce the encrypted text (ciphertext). To make the cipher a little bit stronger, you should convert all letters to uppercase and leave out all spaces between words.

    输入

    The input contains several messages. Each message is described by two lines. The first line contains one integer number N (1 ≤ N ≤ 1000). The second line contains the message. The message will be at most 10000 characters long, it will only contain letters and spaces, and there will be at least one letter in each message.

    The last message is followed by a line containing zero.

    输出

    Description

    To keep privacy of messages and prevent the aliens from reading them, we may use various encryption algorithms. These algorithms encode a message into the so-called ciphertext that is difficult (or impossible) to decode for anyone else than the intended recipient. Transposition ciphers are a type of encryption that do not change the letters of the message but only change their order ("shuffle" the letters). Of course, the shuffling must be reversible to allow later decryption.

    In this problem, we will consider a simple transposition cipher which shuffles the letters in such a way that the decryption algorithm always takes every n-th letter. More specifically: when decrypting, the first letter of the ciphertext is taken first, then the next n-1 letters are (repeatedly) skipped and the next letter taken, and so on until we reach the end of the ciphertext. After that, we repeat the procedure starting with the second letter of the ciphertext, and so on until all letters are used.

    Your task is to implement the encryption algorithm for this cipher. For a given message, produce the encrypted text (ciphertext). To make the cipher a little bit stronger, you should convert all letters to uppercase and leave out all spaces between words.

    Input

    The input contains several messages. Each message is described by two lines. The first line contains one integer number N (1 ≤ N ≤ 1000). The second line contains the message. The message will be at most 10000 characters long, it will only contain letters and spaces, and there will be at least one letter in each message.

    The last message is followed by a line containing zero.

    Output

    For each message, output the ciphertext that, after using the described decryption algorithm, will result in the original message (with all spaces removed and all letters in uppercase).

    Sample Input

    2
    CTU Open Programming Contest
    7
    This is a secret message that noone should ever see Lets encrypt it
    15
    text too short
    0

    Sample Output

    CMTMUIONPGECNOPNRTOEGSRTA
    TESNUECHCAOLERIRGODLYSEENEEPITTEVTTSMHSESIAEAHRETSSTOSN
    TEXTTOOSHORT

    Source

    样例输入

    2
    CTU Open Programming Contest
    7
    This is a secret message that noone should ever see Lets encrypt it
    15
    text too short
    0

    样例输出

    CMTMUIONPGECNOPNRTOEGSRTA
    TESNUECHCAOLERIRGODLYSEENEEPITTEVTTSMHSESIAEAHRETSSTOSN
    TEXTTOOSHORT

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部