11302 - Caesar's Cipher - The Simple Cipher   

Description

Caesar's cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.


The cipher illustrated here uses a left shift of 3,
so that each occurrence of E in the plaintext becomes B in the ciphertext.
(https://en.wikipedia.org/wiki/Caesar_cipher)

In this problem, several lines of plaintext made of only uppercases and spaces are given, and you have to determine what is the correct left shift to make the first letter to be 'A'. Then you have to use the same left shift to generate the ciphertext.

 

Hint:

  1. You can use char ch = getchar() ; to get the first character in the input.
  2. Write a function char cipher( char plain, int shift ) can make your code simpler. You just think about what the new character should be after processing by cipher. For example, the characters ' ' (space) and '\n' (newline) should remain the same.
  3. After you print the first character, use while to process all the other characters:
    while( EOF != (ch = getchar() ) ){
            putchar( cipher( ch, left_shift) ) ;
    }

Input

The input is the plaintext. There are several lines of input. All the characters shoud only be one of 'A'-'Z', spaces, and newline('\n') symbols.

There are at most 10 lines, and each line contains less than 100 characters.

The first character must be an alphabet.

Output

Print the ciphertext. You should find out the correct shift to make the first character be an 'A'.

Sample Input  Download

Sample Output  Download

Tags




Discuss