You have to basically try to kill the person and they'll get the message The problem then is what if you are a first time offender with a short prison sentence. You have a very good chance of getting out and starting over. But if you fight back too well you could end up with a much longer sentence.
I saw a tv show about prison life. One of the guys there was sentenced to a few years for robbery, but ended up killing another prisoner in a fight and now is doing life.
He stopped one attempted rape, but now will live in fear for the rest of his short life.
Short time doesn't matter. It's a matter of survival.
Wanna get raped and get HIV? Wanna be shared around the block? Then don't fight back and let them have you. Then when you leave prision dying of AIDS a short time later, think if it was worth not putting up a fight.
The norms and rules of prison are not the same as the outside. Your short prison sentence doesn't mean much to someone who wants to rape you. You have to play within those rules, not when you are getting out and so forth.