1036. crypto Columns

Source: Internet
Author: User

1036. crypto Columns

Description

The columnar encryption scheme scrambles the letters in a message (or plaintext) using a keyword as your strated in the following example: suppose batboy is the keyword and our message is meet me by the old oak tree. since the keyword has 6 letters, we write
The message (ignoring spacing and punctuation) in a grid with 6 columns, padding with random extra letters as needed:

Meetme
Bytheo
Ldoach
Reenth

Here, we 've padded the message with nth. now the message is printed out by columns, but the columns are printed in the order determined by the letters in the keyword. since a is the letter of the keyword that comes first in the alphabet, column 2 is printed
First. the next letter, B, occurs twice. in the case of a tie like this we print the columns leftmost first, so we print column 1, then column 4. this continues, printing the remaining columns in order 5, 3 and finally 6. so, the order the columns of the grid
Are printed wocould be 2, 1, 4, 5, 3, 6, in this case. this output is called the ciphertext, which in this example wocould be eydemo-rthanmektetoeeoth. your job will be to recover the plaintext when given the keyword and the ciphertext.

Input

There will be multiple input sets. each set will be 2 input lines. the first input line will hold the keyword, which will be no longer than 10 characters and will consist of all uppercase letters. the second line will be the ciphertext, which will be no longer
Than 100 characters and will consist of all uppercase letters. The keyword theend indicates end of input, in which case there will be no ciphertext to follow.

Output

For each input set, output one line that contains the plaintext (with any characters that were added for padding). This line shoshould contain no spacing and shoshould be all uppercase letters.

Sample Input

Batboy
Eydemo-rthanmektetoeeoth
Humding
Eiaahebxoifwehrxonnaalrsumnredexctlftvexpedartaxnaaryiex
Theend
Sample output

Meetmebytheoldoaktreenth
Onceuponatimeinalandfarawaytherelivedthreebearsxxxxxx

 #include <iostream>#include <string>#include <algorithm>using namespace std;int main(){string key;while(cin>>key&&key!="THEEND"){int len=key.length();char arr[20][20],result[20][20];string inpu;cin>>inpu;int row=inpu.length()/len;int temp=0;//cout<<row<<endl;for(int i=0;i<len;i++){for(int j=0;j<row;j++){arr[j][i]=inpu[temp];temp++;}}int a[10]={0};for(int i=0;i<len;i++){char temp=*min_element(key.begin(),key.end());a[i]=key.find(temp);key[a[i]]+=27;}for(int i=0;i<len;i++)for(int j=0;j<row;j++)result[j][a[i]]=arr[j][i];for(int i=0;i<row;i++)for(int j=0;j<len;j++)cout<<result[i][j];cout<<endl;}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.