JSSailem points out an important application of Pythagorean theorem - one I was thinking of sending along myself but stopped short, for at least a couple of reasons - and for your consideration. First - you need to calculate the length to within an inch or so to be successful. To do that you must account for the rake of the mast, the height of the mast base above the transom attachment point, and any and all attachment hardware used when installed. (Like shackles, crevices, D-rings, forks, turn buckles, tangs, and the like) both at the mast and on the transom. perfectly doable, but your work must be accurate and precise to within the throw of the turnbuckle.
If I were doing it,, I would raise the mast with a halyard holding the mast from astern. before doing that, be sure to secure the end of a tape measure to the attachment point on the mast so you can get accurate measurements to your attachment points. Then - take the opportunity to make the back stay a split design. with the mast up and a tape measure attached, you can make really accurate measurements for the fabrication. The split back stay will give you several inches of adjustment instead of just the inch or two a turnbuckle will give. Heck, you could even put a couple of turnbuckles- one on each side of the split. Also - you will have to add an attachment point opposite the existing one. (on my 26 I would add a starboard attachment for example). Rudy at D&R marine can help with the split back stay fixture and the second attachment hardware. The amount of time to accomplish properly is very little different than just replacing a single ...when you don't know what the length is. Either way you go - you won't be wrong. To do a proper job of it you will have to raise the mast either way.
Whatever you do- be sure to have fun with it!
Chris