Problem Description
Column Displacement method is a classical cipher algorithm in the modification of the method of encryption, the following will be divided into a fixed number of characters (such as 5 a group, 5 is a key), in the order of a set of rows neatly arranged, the last less than a group of no characters, the completion of reading by the column into ciphertext.
Like what:
Original: 123456789
Key: 4
Transformed Matrix:
1234
5678
9xxx
(The last few x means no characters, no spaces, no tabs, no characters, same as below)
Ciphertext: 159263748
Another example:
Original: Hello, Welcome to my dream world!
Key: 7
Transformed Matrix:
Hello,
Welcome
To my
Dream W
Orld!xx
Ciphertext:
Hw DOEETRRLLOELLC adoomm!,my E W
It's easy for Bob to implement an encryption device that uses column-shifting, but it seems a little difficult for Bob to figure out how to write a corresponding decryption device, can you help him?
Input
The first line is an integer t, which represents the T group data.
Each set of data contains 2 rows
The first line, a string s (1≤∣s∣≤1e5), represents the ciphertext that was encrypted after the column-shifted method
The second line, an integer K (1≤k≤∣s∣), that represents the key of the original text when it is encrypted using the column conjugation method
Enter a character in the guaranteed cipher string that contains only ASCII code within the [0x20,0x7f] range
Output
For each set of data, first one line is output
Case #i:
It then outputs a line containing a string s_decrypt that represents the plaintext that is obtained after decryption
Sample Input
4
159263748
4
Hw DOEETRRLLOELLC adoomm!,my E W
7
Toodming is best
16
Sokaisan
1
Sample Output
Case #1:
123456789
Case #2:
Hello, Welcome to my dream world!
Case #3:
Toodming is best
Case #4:
Sokaisan
Code
Big water problem, there's nothing to say.
#include <iostream>#include <cstdio>#include <cstring>#include <vector>using namespace STD; vector <char>ans[100010];intMain () {intTCharstr[100010];intKscanf("%d", &t); for(intCC =1; CC <= T; cc++) { for(inti =0; I <100010; i++) ans[i].clear (); GetChar (); Gets (str);scanf("%d", &k);intLen =strlen(str);intMoD = len% K;intZC = len/k; for(inti =0; i < Len; i + = ZC) { for(intj = i; J < i + Zc; J + +) {Ans[j-i].push_back (str[j]); }if(MoD) {Ans[zc].push_back (str[i + ZC]); i++; mod--; } }printf("Case #%d:\n", CC); for(inti =0; I <100010; i++) { for(intj =0; J < Ans[i].size (); J + +) {printf("%c", Ans[i][j]); } }printf("\ n"); }return 0;}
Column Displacement Method decryption