  For a finite $\mathbb{Z}$-algebra $R$, i.e., for a ring which is not
necessarily associative or unitary, but whose additive group is finitely
generated, we construct a decomposition of $R/{\rm Ann}(R)$ into directly
indecomposable factors under weak hypotheses. The method is based on
constructing and decomposing a ring of scalars $S$, and then lifting the
decomposition of $S$ to the bilinear map given by the multiplication of $R$,
and finally to $R/{\rm Ann}(R)$. All steps of the construction are given as
explicit algorithms and it is shown that the entire procedure has a
probabilistic polynomial time complexity in the bit size of the input, except
for the possible need to calculate the prime factorization of one integer. In
particular, in the case when ${\rm Ann}(R) = 0$, these algorithms compute a
direct decomposition of $R$ into directly indecomposable factors.
