Interfacing between technophile and technophobe

NACTF2020 – Dr. J’s Vegetable Factory #3

This is my solution to the NACTF2020 Challenge “Dr. J’s Vegetable Factory #3”.

Challenge #1

After years of collecting plush vegetable toys, Dr. J decided to take on his true passion: starting a vegetable factory. Dr. J is incredibly organized, so he likes all of his vegetables to be in the proper order. In fact, he built a robot “Turnipinator-1000” to alphabetize his vegetables for him! Unfortunately, Dr. J doesn’t know what instructions to give Turnipinator-1000. Can you help him out? 🥬🥕🌽🍆🥦🥒🥑🍄

nc 30267

Give instructions in the form of numbers separated by spaces. Entering the number x will swap the vegetable in position x with the vegetable in position x+1. Positions start at zero, not one. (Dr. J is a programmer after all.) For example, given the following vegetables: Avocado, Brocolli, Eggplant, Daikon Radish, Carrot, one possible solution is “3 2 3”

Avocado, Brocolli, Eggplant, Daikon Radish, Carrot

  1. (swap 3 and 4)

Avocado, Brocolli, Eggplant, Carrot, Daikon Radish

  1. (swap 2 and 3)

Avocado, Brocolli, Carrot, Eggplant, Daikon Radish

  1. (swap 3 and 4)

Avocado, Brocolli, Carrot, Daikon Radish, Eggplant

Challenge #2 adds the following:

Dr. J expanded his vegetable factory and he’s got hundreds of vegetables. Can you give Turnipinator-1000 the right instructions to sort Dr. J’s vegetables? 🥬🥕🌽🍆🥦🥒🥑🍄

Challenge #3 adds the following:

Rahul hates vegetables. Rahul hates vegetables so much that he snuck into Dr. J’s factory at night to sabotage Dr. J’s vegetable production! He brought a sledgehammer and broke the wheels of Dr. J’s robot! 😓 Now the robot is stuck in place, and instead of being able to swap any adjacent elements, it can only swap the elements in positions 0 and 1!

But Dr. J won’t let this incident stop him from giving the people the vegetables they deserve! Dr. J is a problem solver 🧠. He organized his vegetables in a circle, and added a conveyor-belt that allows him shift the positions of the vegetables. He thinks that the conveyor belt should make it possible to sort his vegetables, but he’s not 100% sure. Can you help him out?

nc 30267

Enter letters separated by spaces to sort Dr. J’s vegetables. Entering “c” will activate the conveyor belt and shift all vegetables left one position. Entering “s” will swap the vegetable in position 0 with the vegetable in position 1.

The challenge is solved with the following Python code:

import socket
s = socket.socket()
info = s.recv(4096).decode("utf-8")
response = s.recv(8192).decode("utf-8")
response = response + s.recv(8192).decode("utf-8")
stripList = response.split("\n\n")[1].split(', ')
sortedList = sorted(stripList)
trackSort = []
while stripList != sortedList:
    testList = [stripList[0], stripList[1]]
    if (stripList[0] == sortedList[-1]) and (stripList[1] == sortedList[0]>
    elif [stripList[0], stripList[1]] != sorted(testList):
        stripList[0], stripList[1] = stripList[1], stripList[0]
trackString = " ".join(trackSort) + "\n"
response = s.recv(8192).decode("utf-8")

This spits out the flag:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: