Classification of finite rings: Theory and algorithm