This is my solution to the NACTF2020 Challenge “Dr. J’s Vegetable Factory #2”.
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 challenges.ctfd.io 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
- (swap 3 and 4)
Avocado, Brocolli, Eggplant, Carrot, Daikon Radish
- (swap 2 and 3)
Avocado, Brocolli, Carrot, Eggplant, Daikon Radish
- (swap 3 and 4)
Avocado, Brocolli, Carrot, Daikon Radish, Eggplant
- The20thDuck
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? 🥬🥕🌽🍆🥦🥒🥑🍄
The challenge is solved with the following Python code:
import socket
s = socket.socket()
s.connect(("challenges.ctfd.io",30267))
info = s.recv(4096).decode("utf-8")
print(info)
s.send(b'2\n')
#increase received bytes
response = s.recv(8192).decode("utf-8")
print(response)
stripList = response.split("\n\n")[1].split(', ')
print(stripList)
sortedList = sorted(stripList)
trackSort = []
while stripList != sortedList:
for j in range(len(stripList) - 1):
testList = [stripList[j], stripList[j + 1]]
if [stripList[j], stripList[j + 1]] == sorted(testList):
continue
else:
stripList[j], stripList[j + 1] = stripList[j + 1], stripList[j]
trackSort.append(str(j))
# add \n to return
trackString = " ".join(trackSort) + "\n"
s.send(trackString.encode('utf-8'))
response = s.recv(8192).decode("utf-8")
print(response)
This spits out the flag:
nactf{d0n7_w0rry_p34_h4ppy_f27ae283dd72cb62f685}