optimizing various sbox generation related functions