estás haciendo esto...
A1, A2, A3, A4
B1, B2, B3, B4
C1 = NOT (A1 AND B1)
C2 = NOT (A2 AND B2)
C3 = NOT (A3 AND B3)
C4 = NOT (A4 AND B4)
D = (C1 AND C2) AND (C3 AND C4)
que pasa aquí?
supongamos que el codigo preesstablecido es 1001 e introduces el mismo numero
C1 = NOT (1 AND 1) -> 0
C2 = NOT (0 AND 0) -> 1
C3 = NOT (0 AND 0) -> 1
C4 = NOT (1 AND 1) -> 0
D = (0 AND 1) AND (1 AND 0) -> 0
and solo compara si ambos son 1, en tal caso serían XOR para comparar ya que XOR sería 1 para diferentes 0 para iguales
es decir
C1 = NOT (A1 XOR B1)
C2 = NOT (A2 XOR B2)
C3 = NOT (A3 XOR B3)
C4 = NOT (A4 XOR B4)
D = (C1 AND C2) AND (C3 AND C4)
supongamos que el codigo preesstablecido es 1001 e introduces el mismo numero
C1 = NOT (1 XOR 1) -> 1
C2 = NOT (0 XOR 0) -> 1
C3 = NOT (0 XOR 0) -> 1
C4 = NOT (1 XOR 1) -> 1
D = (1 AND 1) AND (1 AND 1) -> 1