Bandit Level 11

OverTheWire Bandit Challenge Level 11

Bandit Level 11 is designed to teach the basics of the tr command. Tr is a useful command for manipulating text from standard input and sending it to standard output. It’s a bit easier to understand compared to more complex text manipulation commands (like sed and awk).

In this challenge, we know that the password for the next level is rotated 13 characters away from the text in the data.txt file. This means that the letter “A” is actually the letter “N,” the letter “B” is actually an “O,” and so on.

The actual command used to solve this challenge takes a bit of understanding of how this works. I like to demonstrate the use of this command with something more basic. Let’s try shifting all our lowercase characters to uppercase ones. For that, we would enter:

cat data.txt | tr "a-z" "A-Z"

Essentially, the first input of the tr command (“a-z”) is the text we’re looking for (in this case, all lowercase characters), and the second input (“A-Z”) is what we are converting these characters to.

If we want to actually rotate characters, we take the second input to the previous command (“A-Z”) and make some changes. We will start with the 14th letter of the alphabet, “n,” and shift every “a” character to equal that. We want the letters in the second half of the alphabet to be rotated to the front. To do this, the command looks like this:

cat data.txt | tr "a-z" "n-za-m"

The above command will only impact the lowercase characters, but we want to apply this to uppercase characters as well. One way to do this is to pipe the above command into another tr command to get the solution:

cat data.txt | tr "a-z" "n-za-m" | tr "A-Z" "N-ZA-M"

Another way to do this is to merge the commands without an additional pipe:

cat data.txt | tr "a-zA-Z" "n-za-mN-ZA-M"

As you can see, that looks a little strange to the untrained eye! After reading this, I hope you have a better understanding of why this command looks the way it does. If you’d prefer a video, check out the tutorial for level 11 below:

Related Posts