the calculations are sorta hidden, the dev team would know the answer but they may not reveal the whole truth behind it,
Just to let you know, when you upgrade your attack and defense, the idea is to increase your chances of winning a fight, either defending or attacking. So the other person may have upgraded lot more than you have.
Not to mention, some of the items used have a higher defense than it has Attack, therefore, the defender will win the battle not the attacker. (assuming both players have maxed weapons)