Column Displacement Method decryptionAccepts:75submissions:206Time limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others) 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. For example: Original: 123456789 key: 4 transformed matrix: [pre]1234 5678 9xxx[/pre] (the last few x means no character, not a space, not a tab, there is no character, the same as) ciphertext: 159263748 again for example: the original: Hello , Welcome to my dream world! Key: 7 Transformed Matrix: [Pre]hello, Welcome to my dream W orld!xx[/pre] Ciphertext: Hw DOEETRRLLOELLC adoomm!,my E W implementing an encryption using column-shifting method is a breeze for Bob. , however, it seems a little difficult for Bob to figure out how to write a corresponding decryption device, can you help him?
Input
First line an integer T Said T Group data. Each set of data contains 2 Line first line, a string s(1≤|s|≤1e5) , which indicates that the second line, an integer, is encrypted after the column conjugation method. K (1≤K ≤|s|) , which indicates that the key input in the original text is encrypted using the column-shift method to ensure that the cipher string contains only ASCII code [0x -,0x7F ) The characters in the range
Output
For each set of data, output one line of case #i: Then output a line containing a string s_decrypt, which indicates the plaintext that is obtained after decryption
Sample InputCopy
41592637484Hw DOEETRRLLOELLC adoomm!,my e w7toodming is best16sokaisan1
Sample OutputCopy
Case #1:123456789Case #2: Hello, Welcome to my dream world! Case #3: toodming is bestcase #4: Sokaisan
String processing problem, note scnaf with get middle to add GetChar receive line break
#include <stdio.h> #include <string.h>int main () {int T;char str[100005];int k,num=1;scanf ("%d", &t); GetChar (); while (t--) {gets (str); printf ("%s\n", str); scanf ("%d", &k); GetChar ();//printf ("%d\n", K); int Len=strlen (str), int count=len;//The number of characters to output int mod=len%k;//The last line requires the number of characters to be output int a=len/k+1;//printf ("**************%d \ n ", Len);p rintf (" Case #%d:\n ", num++), the for (int i=0;i<a;i++) {int m=a;//m is the output interval int n=mod;int j=i;//The output start position of the current loop while (j <len&&count--) {printf ("%c", Str[j]), if (n<=0) j=j+m-1;//The last line output is finished, the output interval is reduced by one else j+=m; n--;}} printf ("\ n");}}
Fission-bit method to encrypt best coder