Day 13/14: Cracking the Code – the string maketrans function


In this episode we are cracking one challenge from the amazon Python Challenge


In entry two there is a encrypted code that needs some cracking!

If you look closely at the string you notice that all letters are shifted by two. Instead of “abc” its “cde” and so on.

To crack this code we use the maketrans-function.


Here is the code:

import string

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

# the maketrans function transforms our coded string with a new set of letters
table = string.maketrans(
    "abcdefghijklmnopqrstuvwxyz", "cdefghijklmnopqrstuvwxyzab"

# setting up the decoded string for printing.
result = raw.translate(table)


The output looks like this:


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.