Magnetic braiding in a toroidal plasma