We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. LinkedIn Placements
  4. Caesar Cipher: Encryption

Caesar Cipher: Encryption

Problem
Submissions
Leaderboard
Discussions
Editorial

Julius Caesar protected his confidential information by encrypting it in a cipher. Caesar's cipher rotated every letter in a string by a fixed number, , making it unreadable by his enemies. Given a string, , and a number, , encrypt and print the resulting string.

Note: The cipher only encrypts letters; symbols, such as -, remain unencrypted.

Input Format

The first line contains an integer, , which is the length of the unencrypted string.
The second line contains the unencrypted string, .
The third line contains the integer encryption key, , which is the number of letters to rotate.

Constraints


is a valid ASCII string and doesn't contain any spaces.

Output Format

For each test case, print the encoded string.

Sample Input

11
middle-Outz
2

Sample Output

okffng-Qwvb

Explanation

Each unencrypted letter is replaced with the letter occurring spaces after it when listed alphabetically. Think of the alphabet as being both case-sensitive and circular; if rotates past the end of the alphabet, it loops back to the beginning (i.e.: the letter after is , and the letter after is ).

Selected Examples:
(ASCII 109) becomes (ASCII 111).
(ASCII 105) becomes (ASCII 107).
remains the same, as symbols are not encoded.
(ASCII 79) becomes (ASCII 81).
(ASCII 122) becomes (ASCII 98); because is the last letter of the alphabet, (ASCII 97) is the next letter after it in lower-case rotation.

Author

vatsalchanana

Difficulty

Easy

Max Score

40

Submitted By

6162

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy