Infrared (IR) telescopes, such as Spitzer and SOFIA, have revealed a rich variety of chemical species trapped in interstellar ices. The most fundamental parameters to be derived from observed IR spectra are the identity and abundance of each component. Several compounds have been conclusively or tentatively identified, but the band strengths and optical constants needed to derive accurate abundances for many of these are poorly constrained. We have developed a modified approach to the extraction of the real and imaginary parts of the refractive index (optical constants) of a thin film from a single transmission spectrum measured in the IR spectral range. Our algorithm is similar to those implemented by previous authors, with some major changes that yield results for strong absorptions where previous approaches fail: (1) an adaptive k-correction step size, (2) the use of a root-finding algorithm to obtain a more accurate k-correction at each iteration, and (3) a k-correction step that prevents nonphysical results such as negative n-values that prevent convergence in the calculation algorithm. The algorithm is presented and described, with examples to show agreement with some existing results and improvements upon others. New optical-constants calculations for CH3OH, CO2, N2O, and CH4 are presented, and potential implications for the modeling of interstellar and planetary ice data from space telescopes are discussed. With the objective of being open-source and transparent, the full source code in the free Python programming language is made available along with the compiled version and the laboratory data used to produce the results shown.