I am confused by this. Are you talking about being attacked as in being mugged or something? As in biking/walking being unsafe because of crime? Or do people in your hometown attack bikers and pedestrians because they're biking/walking? If it's the second one I'd be interested to hear more about it because that's fascinating.
On a bicycle you have the Highway Code (or equivalent) on your side, you are also able to go into pedestrian mode if need be. Therefore you do not have to stop for anyone or anything if you do not want to. There are softer targets than cyclists and softer cyclists than you. So long as you have your wits about you then there is no need to be apprehended when on a bicycle.
You can even change your route to avoid having to stop, e.g. at a junction. You can also change your pace without arousing suspicion. There is no need to use a 'car park' or other area targeted by thieves. With an unassuming but well locked bicycle you need not have your ride be a cause of concern, even if locked up in an area you do not know well. In some cities parking is so expensive that the loss of a bicycle seat or wheel is 'affordable' risk.
By sticking to the tin box you are part of the problem and not the solution. Cities need regular citizens walking about in them to feel safe.
I'm out and about walking every day now that I live in Seattle; it really depends where you live. Thankfully, I don't believe you know what it's like to be cornered by five guys who want to beat your brains out for no good reason at all other than they are bored and have nothing better to do. At some point it's not worth it. It was a good motivating factor for me to work my ass off to make sure I don't live in such a place.
Actually I was writing with knowledge: I have been mugged, not just your normal mugging, but an ultraviolent mugging. I was on foot, two guys apprehended me, dragged me to the gutter, beat the living daylights out of me - I could see chunks of skin being kicked off my face but because they had kicked my kidneys in I could not feel anything (adrenaline). I heard more footsteps and thought I might be saved. Alas no, another gang joined in, the first of this group smashing a glass bottle on my head as a way of saying hello. After this went on for a while they dragged me to my feet and demanded money at knife point.
I know what I am talking about. My response to this was to ride a bicycle and never be a pedestrian in that bit of town again. I also moved house, seeing my own blood on the pavement was a bit much!