In [1]:
# Create a simple function to do the circular shift on a letter of the alphabet
def alphaShift(asciiCode, shift):
    """Performs a circular shift of the lowercase alphabet
    
    Note: This assumes the character is given as an ASCII character point,
    ie., ord(char)
    """
    min = ord('a')
    max = ord('z') + 1 - min # Offset by 1 so 'z' is included
    normalized = asciiCode - min
    return chr( ((normalized + shift) % max) + min )

In [2]:
# Create our before -> after translation strings
import string
encrypted = string.ascii_lowercase
shifted = ''.join( [alphaShift(c, 2) for c in range(ord('a'), ord('z') + 1)] )

# alternatively, we could create the shifted alphabet with the following command.
# However, this approach isn't reusable like the function is and is intrinsic to a 2 position rotation
shifted_alternate = ''.join( [chr(c) for c in range(ord('a') + 2, ord('z' + 1))]) + ''.join( ['a', 'b'] )

In [4]:
# Create our translation table
transTable = str.maketrans(encrypted, shifted)

In [5]:
# Apply the translation to the cipher text from the web page.
# Multiple lines are used for sanity due to length of the string. It would work fine on one line as well.
# Note: Double quotes are needed!
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."

cleartext = ciphertext.translate(transTable)
print(cleartext)


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 [6]:
# Apply the mapping on the URL because the computer told us to
print("map".translate(transTable))


ocr

In [ ]: