You have two unknowns so you need two equations.
With 12V the wiper of the pot will be at the bottom. That means the voltage divider will be R1 + Rpot above the output and R2 below.
simulate this circuit – Schematic created using CircuitLab
With 4.5V the wiper will be at the top of the pot.
simulate this circuit
No trial and error is required. With the pot at one extreme you'll get 12V as shown in the top schematic. If you understand how to work with voltage dividers, then you can write down an equation for that condition:
$$1.23{\rm\,V} = 12{\rm\,V} \frac{R_2}{R_1+R_{pot}+R_2}$$
With the pot at the other extreme you'll get 4.5V as shown in the bottom schematic. The corresponding equation is:
$$1.23{\rm\,V} = 4.5{\rm\,V} \frac{R_2+R_{pot}}{R_1+R_{pot}+R_2}$$
You know the value of Rpot. (You wrote 5k in your question, but it could be anything.) That means you have two equations with two unknowns: R1 and R2.
Now you need to solve the simultaneous equations, which I'm not going to do for you and is beyond the scope of this question.