docs: function guess_errors() {
  		var el = 0,
  			b = [0, 0, 0, 0, 0],
  			t = [];
  
  		var deg_lambda = 0,
  			lambda = [1, 0, 0, 0, 0]; // error+erasure locator poly
  
  		// Berlekamp-Massey algorithm to determine error+erasure locator polynomial
  
  		for (var r = 0; r < 4; r++) {
  			var discr = calc_discrepancy(lambda, r + 1); // Compute discrepancy at the r-th step in poly-form
  
  			if (discr !== 0) {
  				deg_lambda = 0;
  
  				for (var i = 0; i < 5; i++) {
  					t[i] = lambda[i] ^ gmult(discr, b[i]);
  
  					if (t[i]) deg_lambda = i;
  				}
  
  				if (2 * el <= r) {
  					el = r + 1 - el;
  
  					for (i = 0; i < 5; i++) {
  						b[i] = gmult(lambda[i], ginv(discr));
  					}
  				}
  
  				lambda = t.slice(); // copy
  			}
  
  			b.unshift(0); // shift => mul by x
  		}
  
  		// Find roots of the locator polynomial.
  
  		var errloc = find_errors(lambda);
  
  		var errors = errloc.length;
  
  		if (errors < 1 || errors > 2) return false;
  
  		if (deg_lambda !== errors) return false; // deg(lambda) unequal to number of roots => uncorrectable error
  
  		// Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo x**(4)). Also find deg(omega).
  
  		var omega = [0, 0, 0, 0, 0];
  
  		for (var i = 0; i < 4; i++) {
  			var t = 0;
  
  			for (var j = 0; j < i; j++) {
  				t ^= gmult(syndrome[i + 1 - j], lambda[j]);
  			}
  
  			omega[i] = t;
  		}
  
  		// Compute error values in poly-form.
  
  		for (r = 0; r < errors; r++) {
  			var t = 0;
  			var pos = errloc[r];
  			var root = 31 - pos;
  
  			for (i = 0; i < 4; i++) // evaluate Omega at alpha^(-i)
  			{
  				t ^= gmult(omega[i], gexp[(root * i) % 31]);
  			}
  
  			if (t) // evaluate Lambda' (derivative) at alpha^(-i); all odd powers disappear
  			{
  				var denom = gmult(lambda[1], 1) ^ gmult(lambda[3], gexp[(root * 2) % 31]);
  
  				if (denom === 0) return false;
  
  				if (pos > 12) pos -= 14;
  
  				codeword[pos] ^= gmult(t, ginv(denom));
  			}
  		}
  
  		return true;
  	}