P1079 Vigenère Password
-
- Topic provider Rokua Onlinejudge
- label string simulation forNoip increase group
- Difficulty Popularity-
Submit a discussion of the problem record
Title Description
16th century French diplomat Blaise de Vigenère designed a multi-table cipher encryption algorithm ――vigenère secret
Code. 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 say that the information that needs to be encrypted is clear text, denoted by M, and the encrypted information is ciphertext, with
The key is a parameter, which is the data that is entered in the algorithm that converts plaintext into ciphertext or cipher text into plaintext.
Recorded as K. In the Vigenère password, the key k is a string of letters, K=K1K2...KN. When plaintext is m=m1m2...mn,
Get the 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 ® operation ignores the case of letters that participate in the operation and preserves the case of letters in clear M;
- When the length of the plaintext 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.
Input/output format
Input Format:
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 Format:
Outputs a total of 1 rows, a string representing the plaintext of the input key and ciphertext.
Input/Output sample
Input Sample # #:
Sample # # of output:
Description
"Data description"
For 100% of data, the length of the key entered is not more than 100, the length of the input cipher is not more than 1000, and
All contain only English letters.
NOIP 2012 Raise the first day of the group first question
Analysis: A very simple simulation problem, but note that the ASCII code of a is larger than the ASCII code a, long insight.
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<string>using namespacestd;stringA, B;intWeizhi;CharKey,ans;intMain () {CIN>> a >>b; intLen1 = A.size (), len2 =b.size (); for(inti =0; i < len2; i++) {Weizhi= i%len1; Key=A[weizhi]; if(A[weizhi] >='a') ans= B[i]-(A[weizhi]-'a'); Elseans= B[i]-(A[weizhi]-'A'); if((B[i] >='a'&& ans <'a') || (B[i] <'a'&& ans <'A')) Ans+= -; printf ("%c", ans); } return 0;}
noip2011 Vigenère Password