I'm given an elliptic curve $y^2=x^3+ax+b \in \mathbb{Z}_p[x]$ (with numbers $a,b,p$ not greater than $10^6$).
I would like to find, using the naive approach, the number of affine points on the curve without the point at infinity .
My approach is to go through all $x\in\mathbb{Z}_p$ and check which of them have residue (stored in counter. Since each $x$ has either two or zero residues, I multiply the number of $x$ with residues times 2.
To return the number of affine points, the following method is used:
if isSingular(a,b,p):
return counter*2+2
return counter*2+1
It seems to work for some cases, but not for others. Is there something special we have to consider for singular curves, and why?