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.
- Prepare
- Algorithms
- Strings
- Caesar Cipher
- Discussions
Caesar Cipher
Caesar Cipher
Sort by
recency
|
1241 Discussions
|
Please Login in order to post a comment
!/bin/python3
import math import os import random import re import sys
#
Complete the 'caesarCipher' function below.
#
The function is expected to return a STRING.
The function accepts following parameters:
1. STRING s
2. INTEGER k
#
def caesarCipher(s, k): z = k % 26 test = '' alpahabet = "abcdefghijklmnopqrstuvwxyz" cipher_alphabet = alpahabet[z:] + alpahabet[:z] for x in s: if x.isalpha(): if x.isupper(): a = alpahabet.index(x.lower()) test = test + cipher_alphabet[a].upper() else: a = alpahabet.index(x) test = test + cipher_alphabet[a] else: test = test + x return test
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')
python3
C++ more at https://github.com/IhorVodko/Hackerrank_solutions
java