There are a few ways to do this, here is one.
The trick with this one is to send the power and ground through the two wires and modulate the 12V to encode the STEP and DIR signals onto the 12V line. In the schematic below the top part is your transmitter. Note you need the 12V rail and the 5V rail.
simulate this circuit – Schematic created using CircuitLab
The STEP signal turns the 12V on and off. If the DIR line is low the 5V line takes over for the 12V, if DIR is high the output will be open.
The receiver, shown at the bottom of the schematic, rectifies the signal and regulates it to your required 5V.
At the same time the level is compared against reference voltages created from the regulated 5V to extract the STEP and DIR levels. D3, R6 and C3 delay the STEP signal a little to ensure the DIR signal has sufficient setup time before the rising edge.
Considerations: The values shown were calculated and simulated for 1kHz step rate. Faster step rates may run into timing issues that prevent this circuit from functioning. It is also important to keep the STEP signal low for more than about 60% of the time in order for the PWM effect not to starve the regulator. Note though, holding STEP high will actually turn off the stepper eventually.
If you do not need the DIR line it is a bit simpler.
simulate this circuit
In this version I changed the driver side a little to get rid of the invertor gate. The receiver now is just a simple voltage divider and Schmidt Trigger invertor.
The STEP line should be normally low and only pulsed high for 20-30us or so.
When STEP is low, M1 is on sending 12V to the motor board which charges C1 and lets the regulator power your motor driver. When STEP_IN goes high, M1 turns off and the 12V is cut. The receiver, brings the 12V line down to logic levels via R4 and R5 and D2 makes sure that division never goes over 4.7V. The Schmidt trigger invertor then goes high when the 12V it turned off.
Here is a better version, faster modulation and less ripple on the 5V.