String algorithm

http://pastebin.com/NrWKqfDa

Can someone explain me this algorithm… the task is to divide B to 2 parts and when we swich sides… we get A…
I really need help with this…:confused:

//