An algorithm for the decomposition of semisimple Lie algebras