Logo
(追記) (追記ここまで)

16611번 - Kleptography 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB13512610894.737%

문제

John likes simple ciphers. He had been using the “Caesar” cipher to encrypt his diary until recently, when he learned a hard lesson about its strength by catching his sister Mary browsing through the diary without any problems.

Rapidly searching for an alternative, John found a solution: the famous “Autokey” cipher. He uses a version that takes the 26 lower-case letters ‘a’–‘z’ and internally translates them in alphabetical order to the numbers 0 to 25.

The encryption key k begins with a secret prefix of n letters. Each of the remaining letters of the key is copied from the letters of the plaintext a, so that kn+i = ai for i ≥ 1. Encryption of the plaintext a to the ciphertext b follows the formula bi = ai + ki mod 26.

Mary is not easily discouraged. She was able to get a peek at the last n letters John typed into his diary on the family computer before he noticed her, quickly encrypted the text document with a click, and left. This could be her chance.

입력

The input consists of:

  • One line with two integers n and m (1 ≤ n ≤ 30, n + 1 ≤ m ≤ 100), where n is the length of the keyword as well as the number of letters Mary saw, and m is the length of the text.
  • One line with n lower-case letters, the last n letters of the plaintext.
  • One line with m lower-case letters, the whole ciphertext.

출력

Output the plaintext of John’s diary.

제한

예제 입력 1

5 16
again
pirpumsemoystoal

예제 출력 1

marywasnosyagain

예제 입력 2

1 12
d
fzvfkdocukfu

예제 출력 2

shortkeyword

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > NWERC 2018 K번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /