In [3]:
encoded = [chr((char + 2) % ord('z')) for char in range(ord('a'), ord('z')+1)]

In [22]:
encoded
max


Out[22]:
123

In [26]:
def alphaShift(asciiCode, shift):
    """Performs a circular shift of the lowercase alphabet
    
    Note: This assumes the character is given as an ASCII character point
    """
    min = ord('a')
    max = ord('z') + 1 - min # Offset by 1 so 'z' is included
    normalized = asciiCode - min
    return chr( ((normalized + shift) % max) + min )
print(alphaShift(ord('a'), 26))
print(alphaShift(ord('z'), 27))


a
a

In [14]:
print(ord('z') + 1)
print(ord('a'))


123
97

In [21]:
max


Out[21]:
123

In [16]:
(97-97+2)%123


Out[16]:
2

In [17]:
(123-97+3)%123


Out[17]:
29

In [18]:
chr(29+97)


Out[18]:
'~'

In [31]:
shifted = ''.join([alphaShift(c,2) for c in range(ord('a'),ord('z')+1)])
print(shifted)


cdefghijklmnopqrstuvwxyzab

In [29]:
lower = [c for c in range('a', 'z'+1)]


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-29-99d4cea15cc8> in <module>()
----> 1 lower = [c for c in range('a', 'z'+1)]

TypeError: Can't convert 'int' object to str implicitly

In [33]:
import string
encrypted = string.ascii_lowercase
print(encrypted)


abcdefghijklmnopqrstuvwxyz

In [35]:
transTable = str.maketrans(encrypted, shifted)
transTable2 = str.maketrans(shifted, encrypted)

In [36]:
ciphertext = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."

In [38]:
cleartext1 = ciphertext.translate(transTable)
cleartext2 = ciphertext.translate(transTable2)

print(cleartext1)
print(cleartext2)


i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.
e dkla ukq zezjp pnwjohwpa ep xu dwjz. pdwpo sdwp ykilqpano wna bkn. zkejc ep ej xu dwjz eo ejabbeyeajp wjz pdwp'o sdu pdeo patp eo ok hkjc. qoejc opnejc.iwgapnwjo() eo naykiiajzaz. jks wllhu kj pda qnh.

In [43]:
shifted2 = [alphaShift(ord(c), 2) for c in list(string.ascii_lowercase)]
print(shifted2)


['c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b']

In [56]:
alternate = ''.join( [chr(c) for c in range(ord('a') + 2, ord('z') + 1)] ) + ''.join( ['a', 'b'] )
print(alternate)
print(shifted)


cdefghijklmnopqrstuvwxyzab
cdefghijklmnopqrstuvwxyzab

In [57]:
cipher2 = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. "\
"bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. "\
"sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. "\
"lmu ynnjw ml rfc spj."
print(cipher2)
print(cipher2.translate(transTable))


g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.
i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.

In [ ]:
print("map".translate(transTable)