Dear Ivan,
Yes I know about that. But 367 is 3 mod 4 so it should be OK. And the existing
protocol works with 367 only if the two numbers are not equal. If they are, I
got the error mentioned in my first message.
If I can solve the error in the existing protocol, I will be able to continue
my

I know this is talking around the problem but:
For very small moduli like yours, another protocol for equality is
actually simpler, better (no risk of failing) and faster (I guess):
raise (a-b) to n-1 (with square and multiply), and if this difference
was 0 you will get 0, otherwise you will get