08: Vigen & #232; re password, 08vigen?

Source: Internet
Author: User

08: Vigen? re password, 08vigen?
08: Vigen è re Password

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

In the 16th century, French diplomat blise de Vigen é re designed a multi-Table encryption algorithm-Vigen é re password. Vigen's encryption and decryption algorithms are easy to use and difficult to crack. They have been widely used in the North and South wars in the United States.

In cryptography, we call the information to be encrypted as plain text, expressed in M; the encrypted information as ciphertext, expressed in C; and the key is a parameter, is the data input in the algorithm that converts plaintext to ciphertext or converts ciphertext to plaintext, and is recorded as k. In the Vigen è re password, the key k is a token string, k = k1k2... Kn. When Ming Wen M = m 1m2... The ciphertext C = c1c2... Cn, where ci = mi®Ki, Operation®As shown in the following table:

Note the following when operating Vigen è re encryption:

1.®The operation ignores the uppercase and lowercase letters involved in the operation, and keeps the uppercase and lowercase letters in the plain text M;

2. When the length of the plain text M is greater than the length of the key k, the key k is reused.

For example, when the plaintext M = Helloworld and the key k = abc, the ciphertext C = Hfnlpyosnd.

Plaintext 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
Enter two rows in total.
The first row is a string that indicates the key k and cannot exceed 100 characters in length. It only contains uppercase and lowercase letters. The second act is a string that indicates the encrypted ciphertext. It cannot exceed 1000 characters in length and only contains uppercase and lowercase letters.

For 100% of data, the length of the entered key cannot exceed 100, the length of the entered ciphertext cannot exceed 1000, and only English letters are contained.
Output
The output contains one line. A string indicates the plaintext corresponding to the input key and the ciphertext.
Sample Input
CompleteVictoryYvqgpxaimmklongnzfwpvxmniytm
Sample output
Wherethereisawillthereisaway
Source
Question 1 in NOIP2012 semi-finals
1 # include <iostream> 2 # include <cstring> 3 # include <cstdio> 4 # include <cmath> 5 using namespace std; 6 char my [2, 10001]; // key 7 char miwen [1001]; // ciphertext 8 char mingwen [1001]; // plaintext 9 char zd [101] [101]; // dictionary for storing plaintext and ciphertext keys 10 int yn1 [1001]; // required-32 11 int main () 12 {13 scanf ("% s", & my ); 14 scanf ("% s", & miwen); 15 int lmy = strlen (my); // The key length is 16 int lmiwen = strlen (miwen ); // The plaintext length 17 for (int I = 1; I <= 26; I ++) 18 {19 char bg = (cha R) (I + 64); 20 for (int j = 1; j <= 26-i + 1; j ++) 21 {22 zd [I] [j] = bg; 23 bg ++; 24} 25} // create a dictionary 26 for (int I = 2; I <= 26; I ++) 27 {28 char bg = 64; 29 for (int j = 26-i + 1; j <= 26; j ++) 30 {31 zd [I] [j] = bg; 32 bg ++; 33} 34} 35 for (int I = 0; I <lmy; I ++) 36 {37 if (my [I]> = 90 & my [I] <= 122) 38 my [I] = my [I]-32; 39} // convert all keys to uppercase letters 40 for (int I = 0; I <lmiwen; I ++) 41 {42 if (miwen [I]> = 97 & miwen [I] <= 122) 43 {44 miwen [I] = miwen [I]-32; 45 yn1 [I] = 1; 46} 47} // set Convert all ciphertext data to uppercase letters 48 int cs = lmiwen/lmy + 1; 49 while (cs! = 1) 50 {51 strncat (my, my, lmy); 52 cs --; 53} // copy the key to 54/* for (int I = 1; I <= 26; I ++) 55 {56 for (int j = 1; j <= 26; j ++) 57 {58 cout <zd [I] [j] <""; 59} 60 cout <endl; 61} // create a dictionary */62 for (int I = 0; I <lmiwen; I ++) 63 {64 int amy = (int) my [I]; // ascll code table 65 int amw = (int) miwen [I] for the key corresponding to the ciphertext; // ascll code Table 66 if (amy <= amw) for the I-th ciphertext) 67 {68 if (yn1 [I] = 1) 69 {70 cout <(char) (amw-amy + 65 + 32 ); 71} 72 else cout <(char) (amw-amy + 65); 73} 74 else75 // cout <(char) (amy-amw + 73 ); 76 {77 int now = 0; 78 for (int j = 1; j <= 26; j ++) 79 {80 if (zd [26] [j] = amw) 81 {82 now = 26 + j; 83 break; 84} 85} 86 if (yn1 [I] = 1) 87 {88 cout <char (now-(amy-64) + 64 + 32 ); 89} 90 else cout <char (now-(amy-64) + 64); 91} 92} 93 return 0; 94}

 

Related Article

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.