Probability for Vigenere cipher given distribution of key lengths Given the exact same question and answer here: https://crypto.stackexchange.com/a/37212/40935.

How does one derive/figure out (using equation, combination of equations, or "knowledge") the bold marked parts in the following:


  How does one know to put 0.5 and 1/(26^2) in the following places:
  
  
  Pr[C=ff | M=dd] x Pr[M=dd] = [1/26 x 0.5 + 1/(26^2) x 0.5] x 0.2
  Pr[C=ff | M=de] x Pr[M=de] = [0 x 0.5 + 1/(26^2) x 0.5] x 0.8
  


I expected the conditional part calculations to be:


  
  Pr[C=ff | M=dd] = [1/26 x 0.5 + 1/(26) x 0.5]
  Pr[C=ff | M=de] = [0 x 0.5 + 1/(26) x 0.5]
  


So I would like an "equation" possibly based on the law of total probability and/or Bayes' Theorem (or something which I do not know about), such that I can see the symbolic manipulation/calculations which leads to the simple substitution of values as described above.
Okay, let's take this one apart piece by piece, with $l$ indicating keylength:

You have:


$P(l=1) = P(l=2) = 0.5$
$P(m=dd) = 0.8, P(m=de) = 0.2$
You want to know $P(c=ff)$
Implicitly, we assume that the keys are uniform random (actually not true for Vigenere with actual keywords, but there is no statement in the question).So for any combination of $c,m$, we get a probability of $1/26$ if $l=1$ and $1/26^2$ if $l=2$
Implicitly, the key is independent of the message - pretty standard assumption. And of course $l$ is independent as well.


So let's look at the case $l= 1$. Formally we express that as $P(.|l=1)$. This is a conditional probability, because we place the condition $l=1$.

So: $P(c=ff|l=1) = P(c=ff| l = 1 \cap m=de) + P(c=ff | l = 1 \cap m=dd)$
$  = 0 * 1/26 + 1 * 1/26$   (the $0$ indicates "this is not possible", the $1$ indicates "this is possible with exactly $1$ combination")

Analouge: $P(c=ff|l=2) = P(c=ff|l=2 \cap m=de) + P(c=ff|l=2 \cap m=dd)$
$ = 1 *  1/26^2 + 1 * 1/26^2$ (both possible with exactly one combination, so both $1$s)

Now, we want to get $P(c=ff) = P(c=ff|l = 1) \cdot P(l=1) + P(c=ff|l=2) \cdot P(l=2)$
$= (0+1/26) \cdot 0.5 + (1/26^2 + 1/26^2) \cdot 0.5 = 0.5(1/26 + 2/26^2)$
We just use, that the events $l=1$ and $l=2$ are mutually exclusive. And they happen to be the only possibilities we have to consider.

In the end, we get to the same conclusion as your other questions: You missed the condition on $l$ in your first approach. And then in your solution you incorporated it - but missed out on expressing it in the formulas correctly.