Refactor attack method to brute force boundary value x0 along with keys a and k. Also, use more helper methods for readability.