*For the full experience with images see the original blog post!*
**TL;DR:** parallelism was a reversing challenge using cooperative data shuffling with eight processes.I solved it by analyzing the program and implementing its inverse in Python to reconstruct the flag.
I started out the CTF with this challenge because I just recently worked with MPI for my studies and was intrigued to find out what the author had prepared for us.For those not familiar with MPI is short for message passing interface.It defines protocols and methods for synchronization and data distribution over multiple processes working cooperatively on a problem in parallel.The challenge uses a common implementation, OpenMPI, which supports C and uses the `mpirun` command we were given.Thus, I expected a C program and quickly imported it into ghidra for analysis.(If you're starting out with ghidra reversing, I can recommend [stacksmashing](https://www.youtube.com/@stacksmashing) for an introduction.)
Starting out, I clicked through the few functions to find the entry an main method with their common structure.In the main method, the program initializes and MPI and gets the number of processes and the rank (the number identifying a process), which is the number of the current process.We can see that the program always runs with 8 processes and uses three steps for probably checking the flag.
The first method I called scatter reads our input when run on the main process and expects a line with a 64-character string.It then uses an array of 32 indices to shuffle this string by swapping the character at the given index with the one offset by 31.Finally, it uses MPI_Scatter, a method for distributing a block of data equally between processes, to split the input in blocks of eight characters.
Next, the program implements 10.000 rounds of another shuffle.Each round, each process sends the character at a given offset (`i % 8`) to the process before it, by the same offset to its own rank.It then receives its character and waits for the operations to complete since the program uses the non-blocking method variants.Then, it updates its buffer and synchronizes with the other processes at a barrier before starting the next round.
The last method of the program gathers the message parts from the processes which is the inverse of scatter.Then, it compares the result to a string constant on the main process to determine whether it is the flag.
After looking at the program shortly, I decided I understood it enough to implement the reverse process in python (I'm pretty used to that now).I managed to forget a zero for the round number but fixed that soon after to produce the following program:
```pythonCOMM_SIZE = 8
POS = [0] * 32POS[0] = 0x1aPOS[1] = 0x20POS[2] = 0xePOS[3] = 0xbPOS[4] = 3POS[5] = 1POS[6] = 0x20POS[7] = 0x18POS[8] = 0xdPOS[9] = 0x11POS[10] = 3POS[11] = 0x11POS[12] = 2POS[13] = 0xdPOS[14] = 0x13POS[15] = 6POS[16] = 0xcPOS[17] = 0x16POS[18] = 3POS[19] = 0x1ePOS[20] = 10POS[21] = 6POS[22] = 8POS[23] = 0x1aPOS[24] = 6POS[25] = 0x16POS[26] = 0xdPOS[27] = 1POS[28] = 0x13POS[29] = 1POS[30] = 1POS[31] = 0x1dEXP = "m_ERpmfrNkekU4_4asI_Tra1e_4l_c4_GCDlryidS3{Ptsu9i}13Es4V73M4_ans"
BUFFER = [0]*8# Inverse gatherfor i in range(8):    BUFFER[i] = list(EXP[i*8:i*8+8])
# Inverse of parallel shufflefor i in range(10000):    i = 10000 - i - 1
    tmp = [0] * 8    for COMM_RANK in range(8):        offset = i % 8        dest = (COMM_SIZE + (COMM_RANK - i) % COMM_SIZE) % COMM_SIZE        tmp[COMM_RANK] = BUFFER[dest][offset]    # Splitting here to avoid loosing values    for COMM_RANK in range(8):        BUFFER[COMM_RANK][offset] = tmp[COMM_RANK]
# Inverse of scatter and start shuffleinput = []for i in range(COMM_SIZE):    input += BUFFER[i]
for i in range(0x20):    i = 0x20 - i - 1    current = input[i]    input[i] = input[POS[i] + 31]    input[POS[i] + 31] = current
print("".join(input))```
Of course, the challenge was pretty simple and I managed that primarily because people start with different challenges depending on their preferences.I was happy nonetheless to be able to claim the first-blood for my team.