Caesar cipher P33371


Statement
 

pdf   zip

thehtml

Write a program that encrypts messages with the “Caesar cipher”, used by Julius Caesar to communicate with his generals. Given a constant k, each letter of the original message is replaced by the letter that is alphabetically k positions to its right (circularly, if needed). For instance, if k = 5, we must change ‘a’ by ‘f’, ‘b’ by ‘g’, …, ‘y’ by ‘d’, and ‘z’ by ‘e’.

To solve this exercise, it can be useful a function

char encoded(char c, int k);

that returns the character corresponding to c when the constant is k.

Input

Input consists of several cases. Each case begins with a natural number k > 0, followed by a text made up of only lowercase letters and separator characters, but with no spaces, and ended with a dot.

Output

For each case, print in a line the encrypted text, using uppercase letters. Replace each ‘_’ with a space, and leave unchanged the rest of separator characters.

Public test cases
  • Input

    1
    i_am_an_example.
    
    22
    veni,vidi,vinci.
    
    26000031
    yzznhzzn-eznczo-wjiz-yjnzaz_ypqzhv-zidozhjnn.
    

    Output

    J BN BO FYBNQMF
    RAJE,REZE,REJYE
    DEESMEES-JESHET-BONE-DOSEFE DUVEMA-ENITEMOSS
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Java Python
    User solutions
    C++ Java Python