aboutsummaryrefslogtreecommitdiff
path: root/challenge-097/paulo-custodio/python/ch-1.py
blob: 374dbc9f5fc093ac5185a201901fea1c9db64a73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python

# Challenge 097
#
# TASK #1 › Caesar Cipher
# Submitted by: Mohammad S Anwar
# You are given string $S containing alphabets A..Z only and a number $N.
#
# Write a script to encrypt the given string $S using Caesar Cipher with left
# shift of size $N.
#
# Example
# Input: $S = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG", $N = 3
# Output: "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD"
#
# Plain:    ABCDEFGHIJKLMNOPQRSTUVWXYZ
# Cipher:   XYZABCDEFGHIJKLMNOPQRSTUVW
#
# Plaintext:  THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
# Ciphertext: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD

import sys

def caeser(n, words):
    output = []
    for word in words:
        codes = [(ord(c)-ord('A')+26-n)%26 for c in word.upper()]
        cipher = [chr(i+ord('A')) for i in codes]
        output.append("".join(cipher))
    return output

n = int(sys.argv[1])
words = sys.argv[2:]
print(" ".join(caeser(n, words)))