OUTPUT siganl synchronized with INPUT signal to encode bitstream

Hello world :)

My project is to make a signal to be OUTPUT from arduino when a rotary encoder (or other sensors) signal is input to arduino.

Basicly I am working in the field of magstripe encoding BUT I don't deal with standard decoding and encoding. I want to make something different with custom porgramable bits to magstripe. This can be used as copy protection on custom card or ticket keys and many others. I need to syncronize a rotary encoder with the output of the signal - for example to be able to encode perdefined (custom) signal in the form of "1" and "0". If I want to encode for example - 111111111001111110111111111 I want to program arduino to output signals HIGH for "1 "and to switch polarity of the output pins to write LOW "0". I want to make the signal this way that the frequency of the "1" is exactly twice (or cutom format) the frequency of "0" . The most important is to use the rotary encoder as triger for the signals. For example I have to be able to switch polarity of the OUTPUT signal when the rotary switch send signal to arduino after that Arduino sends signal to the head to write HIGH. (other sensors can be used to monitor the speed or position of the card) This way I can have consistent encoding every time I swipe the magnetic stripe. The signal will be fed to amplifier first to rise it to 9 or 12 volts so the head could write actual bits to magstripe. Basicly what I need is: - switch polarity of the OUTPUT pins or control circuit that changes the OUTPUT polarity - this is importnat because the bits are written by changing polarity of the magnetic head - to be able to change the timebetween two signals - OUTPUT signal to be able to make "0" wave last longer than "1" wave - to be able to use text in bit format "1111110111001111111100111111" to be interpreted as OUTPUT signals from arduino

I know this is possible beacuse I saw an article for magnetic stripe reader using arduino, but I need to use arduino as controller for the signal to be written in magnetic stripe.

I have the basic concept in my head but I can't figure from where to start, thats why I post the project here.

Start off simply, get your hardware writing bits to the mag stripe writer. Implement a convention mag stripe read / write. Only then extend it to your external clock sachem.