There are no simple algorithms, because solutions are style dependent, covering the range from parallel transposition of house chords to a full Baroque counterpoint solver, via pop, rock, and jazz theory.
The question isn't can you do it - because you can, with varying degrees of difficulty.
The question is what specific user problem you're trying to solve.