It depends what you understand by hacking:
- unauthorized entry into a system/network;
- modifying a system to behave the way you need, beyond its original purpose.
First category can have black hat and white hat hacking. As the name implies white is a beneficial hacker and black is the nasty one (usually portrayed by Hollywood as the incarnation of evil).
The second category includes almost all the computer programmers, because many programmers just piece together code already written by others, to obtain a software product. There are very phew cases where the average programmer needs to write its own algorithms.
I can recommend you the games made by exosyphen studios where you can make an idea what hacking is and does.
Just about any activity can be made exciting and just about any can be made boring. When I'm considering an approach, I don't think is this good or exciting or whatever. I have to think: can I as author make it good or exciting or whatever.
Movie/TV labors under certain constraints. The most difficult is making whatever is happening on the secondary screen--the one the characters are looking at--readable and understandable to the users. The best handling of this I've seen is Halt and Catch Fire. You'll notice it's not the programming that the engaging part, it's the character interaction around the screen that really counts. Probably the worst example is "Unix. I know this!" from Jurassic Park.
Hacking specifically? I can't cite anything. My favorite silliness is War Games with the 40 character screen zooming past on a 300 baud modem. But you know what? It didn't matter. It was Matt Broderick's reactions that sold it.
Doing hacking in prose is both easier and more difficult, but the key is still going to be the situation, the stakes, and the characters. One possible avenue would be social engineering. Follow the character through attempts to talk or trick someone out of a key password. Who needs algorithms when we've got people!
The best portrayals are those of the enigmatic, faceless persona that resists capture and unmasking while at the same time becoming well known and held in awe. Their very myth would be the most exciting thing about them, while their real life would be quite sedate by design.
What about the cyberpunk novels? It seems common to present some sort of metaphor for hacking or using the internet: flying through a landscape, for instance. Would something like that work in this situation?
I have to agree with Sknox. The hack essentially, presumably, is a plot device for wider events.
Funnily enough I've just finished a novel in which one of the main characters is a hacker in a small cyber terror collective, and for me the critical thing was to convey that the character knew their onions when it came to the hacking, but not put too much focus on the act of hacking itself. That is, you can play up the stakes of the hacking, or what might happen if the hack goes wrong, but don't detail the hack itself; instead show its consequences.
I did make one exception, where a hack is successfully repelled by a booby trapped defence mechanism disguised as a gap in the target's code, where I included a few lines of pseudo-code because I was showing things from her (the hacker's) perspective, and she was seeing. So the drama from the scene is about the decision she has to make (whether to pull the plug or not - there are consequences either way) in the face of something she's not seen before, and her reactions to it. I don't think you can wring drama out of the basic act of hacking itself, which is essentially somebody hitting "Execute" and sitting back. We're allowed a certain amount of licence in fiction