Encryptastrophy

시간 제한1초메모리 제한2048 MB

요약
키가 직전 평문 문자인 암호문이 주어지고 마지막 평문 글자를 알 때, 원래 평문을 복원한다.
난이도

쉬움10점 중 3점

유형
구현, 수학, 배열
정답자
아직 제출이 없습니다

문제

Alice and Bob are deeply in love, they sometimes like to swap out messages in class because they can't get enough of each other. In order to make sure no-one but them reads these messages, they get together and devise an encryption scheme that is theirs only: Despite what people are saying, security through obscurity does work, right?

To keep things simple, They first map every letter of the alphabet a-z to the numbers 0 to 25.

To encrypt and decrypt, a modular addition cipher is used, which defines the encryption function EE and decryption function DD as such:

E(k,p)=p+kmod  26E(k, p) = p + k \mod 26 D(k,c)=c−kmod  26D(k, c) = c - k \mod 26

c_i=E(k_i,p_i)c\_i = E(k\_i, p\_i) p_i=D(k_i,c_i)p\_i = D(k\_i, c\_i)

Where pp is the plaintext, cc is the ciphertext and kk is the key.

In order to avoid having to send long keys, they define the key as follows:

k_i=p_i−1k\_i = p\_{i-1}

With k_0k\_0 being predetermined by Bob and Alice.

They feel this is secure and chat away all day long, without a worry in the world.

Eve however, has devised a plan. While spying on them, she's always picked up the last letter of every message that they've sent. She's now bent on figuring out what these messages say.

입력

  • One line with one integer: 1≤n≤1031 \leq n \leq 10^3, the length of the ciphertext string
  • One line with the ciphertext string
  • One line with the last letter of the plaintext string

출력

The plaintext string

예제2

  1. 예제 1

    입력
    8
    ftzjzcmi
    u
    
    예상 출력
    iloveyou
    
  2. 예제 2

    입력
    10
    ulpwzkkfco
    d
    
    예상 출력
    helloworld