Optimized encrypt/decrypt for loop by factoring out S-boxes substition