Example of CHI Square test on Caesar Cipher?
I'll assume that the objective is to assert if the distribution of the $f&#39;_i/n&#39;$ is sufficiently similar with the distribution of the $f_i/n$ to support that a substitution cipher (including Caesar cipher) with the same permutation table and same frequency of plaintext characters could be used in both case.

If $n \gg n&#39;$, $f_i \gg 5$ and $f&#39;_i \ge 5$ for each $i$, we can use the first sample as reference; the expected $f&#39;_i$ is $n&#39;&#183;f_i/n$, and the usual Chi-squared test is now to compute (update: formula and condition fixed)

$$X = \sum_{i = 1}^k \frac{(f&#39;_i-n&#39;&#183;f_i/n)^2}{n&#39;&#183;f_i/n} = \sum_{i = 1}^k \frac{(n&#183;f&#39;_i-n&#39;&#183;f_i)^2}{n&#183;n&#39;&#183;f_i}$$

which should be distributed as a Chi-squared variable with $k-1$ degree of liberty under the null hypothesis. We can reject the null hypothesis (substitution cipher with same permutation table and frequency of plaintext characters, assumed independent) if $X$ is bigger than found in a table for Chi-squared confidence test. E.g. for $k$ = 27 and $X$ > 38.9, we reject the null hypothesis with confidence level 95%. CAUTION: we have disregarded the fact that letters in the plaintext are not independent, and this will tend to make $X$ bigger than predicted by the null hypothesis.

If some $f&#39;_i$ (or $f_i$) are too small, an option is to aggregate the smaller ones into a single value (and reduce $k$ accordingly).

If fail to find a reference on what to do when $n$ and $n&#39;$ are of the same order of magnitude.