Report on the problem of Zoj 1006 in Zhejiang University

Source: Internet
Author: User

1006 questions, this problem in fact, the overall is not difficult, to say that rare words do translate more difficult (may be my English is really bad), but as long as you understand the specific key words can be easily understood.

The whole meaning is probably to say that the process of encrypting and decrypting (according to the meaning of the topic), the whole test instructions means to give an intermediate value K and a string is ciphertext (the encrypted string), and then you need to follow the corresponding relationship given in the topic ("' = 0, ' A ' =1, ' b ' = 2, ..., ' Z ' = 26, '. ' =27) ciphertext corresponds to the Ciphercode (string corresponding to the number of cryptographic strings), and then by giving the formula Ciphercode[i] = (plaincode[ki mod n]-i) MoD 28,n represents the length of the cipher string. Make some transformations for plaincode[(i*k)%ciphertext.size ()] = ((ciphercode[i]+i)%28), and then use this formula to figure out the plaincode of each bit (the number string for the original text of the password). Then in the correspondence given by the topic ("' = 0, ' A ' =1, ' B ' =2, ..., ' z ' = 26, '. ') =27) came to plaintext,
Then you can output the plaintext.

And then on the code

#include <iostream> #include <string> using namespace std;
    int main () {int ciphercode[1000],plaincode[1000];
    string ciphertext;
    Char plaintext[1000];
    int k;
        while (cin>>k) {if (k==0) {break;
        } cin>>ciphertext;
            for (int i=0;i<ciphertext.size (); i++) {if (ciphertext[i]== '. ')
            {ciphercode[i]=27;
            } else if (ciphertext[i]== ' _ ') {ciphercode[i]=0;
            } else {ciphercode[i]=ciphertext[i]-' a ' +1; }} for (int i=0;i<ciphertext.size (); i++) {plaincode[(i*k)%ciphertext.size ()] = ((c
        Iphercode[i]+i)%28);
                } for (int i=0;i<ciphertext.size (); i++) {if (plaincode[i]==27) {
            Plaintext[i]= '. ';
      } else if (plaincode[i]==0)      {plaintext[i]= ' _ ';
            } else {Plaintext[i] = plaincode[i]+ ' a '-1;
        }} for (int i=0;i<ciphertext.size (); i++) {cout<<plaintext[i];

    } cout<<endl; }
}

Finished ~

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.