Factoring the code and using a general check algorithm structure, currently inherited by weighted_sum_algorithm and verhoeff.