Noip201205vigenère Password

Source: Internet
Author: User

noip201205vigenère Password

"Problem description"
16th century French diplomat Blaise de Vigenère designed a multi-table cipher encryption algorithm--vigenère password. The encryption and decryption algorithm of Vigenère cipher is simple and easy to use, and it is more difficult to decipher, which was used in the American Civil War
Widely used by the South Army.
In cryptography, we call the information that needs to be encrypted to be plaintext, denoted by M, the encrypted information is ciphertext, denoted by C, and the key is a parameter, which is the data entered in the algorithm that converts plaintext into ciphertext or cipher text into plaintext, denoted as K. In the Vigenère password, the key k is a string of letters, K=K1K2...KN. When plaintext is m=m1m2...mn, the resulting ciphertext c=c1c2...cn, where Ci=mi®ki, the rules of the Operations ® are shown in the following table:

Vigenère encryption should be noted when operating:
The 1.® operation ignores the case of letters that participate in the operation and preserves the case of letters in clear m;
2. When the length of clear text m is greater than the length of the key K, the key k is reused.
For example, plaintext M=helloworld, key k=abc, ciphertext c=hfnlpyosnd.
Clear text H e l l o w o R l D
Key A b c A b c a B c a
Ciphertext H f n L p y o s n d

Input
The input file name is vigenere.in.
Enter a total of 2 rows.
The first behavior is a string that represents the key K, which is not more than 100 in length, and contains only uppercase and lowercase letters. Second line
is a string that represents the encrypted ciphertext with a length of not more than 1000, which contains only uppercase and lowercase letters.

Output
The output file name is Vigenere.out.
Outputs a total of 1 rows, a string representing the plaintext of the input key and ciphertext.

"Input and Output sample"

Vigenere.in Vigenere.out
Completevictory
Yvqgpxaimmklongnzfwpvxmniytm
Wherethereisawillthereisaway


"Data description"
For 100% of the data, enter the key length of not more than 100, the length of the input cipher is not more than 1000, and all contain only English letters.

1#include <iostream>2#include <cstring>3 using namespacestd;4 intMain ()5 {6     intw[ -],i,lk,lh;7     Chark[ -],h[1001],ans[1001];8Cin>>k>>h;9lk=strlen (k);TenLh=strlen (h); One      for(i=0; i<lk;i++) A     { -         if(k[i]>='a') w[i]=k[i]-'a'; -         Elsew[i]=k[i]-'A'; the     } -I=0; -      while(i<LH) -     { +ans[i]=h[i]-w[i%LK]; -         if((ans[i]<'A')|| (ans[i]<'a'&&h[i]>='a')) ans[i]=ans[i]+ -; +cout<<Ans[i]; Ai++; at     } -}
View Code

Noip201205vigenère Password

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.