noip2011 Vigenère Password

Source: Internet
Author: User

P1079 Vigenère Password
      • 677 through
      • 1.3K Submit
    • 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:

    1. The ® 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 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

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.