#CT00041. Mật mã hồi tiếp (Feedback Cipher)
Mật mã hồi tiếp (Feedback Cipher)
Feedback Cipher
Version: Phuoc Hung OJ Extended
Problem Statement
Use lowercase letters a..z with values a , b , , z .
Initially the current key is , where . At position , let be the numeric value of the plaintext character and the numeric value of the ciphertext character.
For encryption,
After processing position , update
For decryption, recover
then update the key using the recovered in the same way.
If , encrypt . If , decrypt . Processing is always performed from left to right.
Input
- Line 1 contains integers and , where and .
- Line 2 contains , consisting only of lowercase letters
a..z.
Output
Print the resulting string after applying the requested mode.
Subtasks
- Subtask 1 (40 points): .
- Subtask 2 (60 points): .
Examples
Example 1
Input
1 3
hello
Output
kpbnc
Explanation
Initially . The value of h is , so the first encrypted value is , which is k. The key then becomes . Continuing from left to right produces kpbnc.
Example 2
Input
2 3
kpbnc
Output
hello
Explanation
Initially . The value of encrypted k is , so the first plaintext value is , which is h. Updating the key with each recovered plaintext value and continuing left to right reconstructs hello.
Liên quan
Trong các cuộc thi sau:
Phước Hưng - Kỳ Thi HSG Lớp 9 (Chuyên đề Xử Lý Chuỗi) - Đề Số 3