from sys import argv
from _codecs import encode
from base64 import b64encode, b64decode

import sys


def a(string):
    return encode(string, 'rot_13')

def c(s):
    x = []
    for i in xrange(len(s)):
        j = ord(s[i])
        if j >= 33 and j <= 126:
            x.append(chr(33 + ((j + 14) % 94)))
        else:
            x.append(s[i])
    return ''.join(x)

def b(string):
    return b64encode(string)
def d(string):
    return b64decode(string)

if len(argv) < 3:
    print """Usage:
python taiga_46.py <type> <text>
    type:
        - b     base64
        - d     base64_decode (for testing)
        - a     rot13
        - c     rot47

for example: python taiga46.py bbac test return rot47(rot13(base64(base64("test"))))
"""
    exit(0)

text = " ".join(argv[2:])
result = text

for letter in argv[1]:
    if letter == "a":
        result = a(result)
    elif letter == "b":
        result = b(result)
    elif letter == "c":
        result = c(result)
    elif letter == "d":
        result = d(result)

print result
