The first rule of surviving a crocodile attack is not to get attacked by one -w-, when that doesn't work however the first thing you need to do is keep it out of the water, now chances are, it weighs more than you, and its definitely stronger than you. So assuming you are not in the water getting it off is pretty easy, poke it in the eyes and it will let go, food that can hurt you isn't worth keeping -w-.
Now if you go in the water with it, there are 2 things you need to realize, 1. its going to try and drown you, 2 you're in deep sh*t. Now when they are under water they close their eyes, so option one is out. SOOOO and this is important, coz you only have as long as you can hold your breath to accomplish this. In the back of it's throat is some muscle tissue, the Crocodile uses this to hold its breath, you have to get an arm or leg down there to open it and the crocodile will let go. The animal will start to drown it will only be for 5 seconds so get the h*ll away while you got the chance.