What portal are you at? If you are referring to a teleporter pad surrounded by 3 pyramids on pedestals, you do not need to activate it to leave. It would provide a shortcut to the exit, but you are 3/4 of the way there anyway.
You should be able to run past most of the opponents there, with just a few closed doors/gates to slow you down. If you have any shadow potions or statuettes, they could help with that (if you washed the dishes in the castle, the cook would have given you a 'strange spice' shadow potion).
If you have a save before entering the castle, you could always reload and wait until you are a higher level. I did much of Rivertown and Verdistis, and cleared the Rivertown sewers before heading to the castle, and didn't have much trouble with most of the opponents there.
Generally speaking, it is better to explore and do side quests first, and then complete the main quests. You don't want to leave quests so long you forget about them, though, or do a later quest that causes you to miss out on an earlier one (ie if you do not arrange an escort for the healers before completing any of the quests that give you an invitation to the castle, they will move on their own).
You don't need to hex edit to get
restoration potions. At least in the disk version, there is a simple exploit to duplicate items which can be stacked.
Drag a stack out of (or into) your inventory (or container) and hold down the control key before dropping. This will bring up the split stack pane; type in a negative number and hit enter (the checkmark will be greyed out). This can also be done in the trade window.
I don't know if this was fixed in the download version, but if so you could try the
Lost Items procedure, or simply use
DAD's item editor to give some crappy piece of equipment great bonuses, to equip long enough to get out of the dungeon. I don't know if either has been tried with the download version.