\font\largerbold = cmbx10 scaled \magstep1
\font\largerrm = cmr10 scaled \magstep1
\font\largestbold = cmbx10 scaled \magstep2
\font\largerrm =cmr10 scaled \magstep1
\def\mycirc{\raise .1em\hbox{$\scriptstyle\bigcirc$}}
\def\tri{$\triangle$} 
\def\di{$diamondsuit$}
\input amssym.def
\font\seventt = cmtt10.tfm scaled 800
\nopagenumbers
\magnification=\magstep1
\parindent=0pt
\rightline{\sevenrm March 26, 2000}

\centerline{\largerbold Bitstream exercises in class} 

\bigskip

{\bf Background assumptions} Our messages in bitstreams will be a
succession of words which will be one of three types (the given
percentage frequencies are approximate):

\medskip 

%\def\cl{$\clubsuit$}

$\bullet$ 50\% of the words are 1010101010. This is 10 bits long,
alternating 1's and 0's. Call it {\bf P}.

\smallskip

%\def\ht{$\heartsuit$}

$\bullet$ 25\% of the words are 1111111. This is 7 bits long, all
1's. Call it {\bf Q}.

\smallskip

$\bullet$ 25\% of the words are 000000. This is 6 bits
long, all 0's. Call it {\bf R}.

\medskip

We'll call bitstreams composed of these words, sentences. The sentence
{\bf R}{\bf Q}{\bf P}{\bf R} is:

\smallskip

\centerline{\tt 00000011111111010101010000000}

\smallskip

Bitstreams will divided into groups of five bits each to make it
easier to refer to parts of them. Then the sentence above is written:


\smallskip

\centerline{\tt 00000 01111 11110 10101 01000 0000}

\bigskip
\hrule\smallskip\hrule
\bigskip\smallskip

{\bf Problem 1} 

Write the following sentence in terms of {\bf P}, {\bf
Q}, and {\bf R}.

\medskip

{\tt 10101 01010 11111 11101 01010 10000 00010 10101 01011 11111 10101
01010}


\def\ans{\bigskip\rightline{\bf Answer\ \ \vrule width 1.2in height
.7pt depth 0pt}}

%\ans
\medskip
\bigskip\medskip
\hrule\smallskip\hrule
\bigskip\medskip

{\bf Problem 2} 

Here is a sentence which has been xored with a
pseudorandom bitstream with approximately 10\% 1's. Write the
original sentence in terms of {\bf P}, {\bf Q}, and {\bf R}.

\smallskip
{\tt
11011 11101 01010 10101 00010 10001 01010 00010 00010 10101 01011 11011 
}

%\ans
\medskip
\bigskip\medskip
\hrule\smallskip\hrule
\bigskip\medskip

{\bf Problem 3} 

The following bitstream is two sentences xored together. Write the
original sentences in terms of {\bf P}, {\bf Q}, and {\bf R} as well
as you can.

\smallskip

{\tt 01010 10111 10101 01000 00000 00101 01000 00101 01001 01010 11110
10101 } 

%\ans
\overfullrule=0pt
\medskip
\bigskip\medskip
\hrule\smallskip\hrule
\bigskip
\medskip
{\bf Problem 4} 

A pseudorandom bitstream with approximately 50\% 1's and 50\% 0's has
been created. Two \underbar{different} sentences have been xored with
it and the results are shown. Write the original sentences in terms of
{\bf P}, {\bf Q}, and {\bf R} as well as you can.

\medskip
{\tt
11110 00111 00101 10010 10010 10011 11101 11110 00100 10111 01110 11011 100}
\medskip

{\tt
11110 00111 10000 10010 11000 00110 10111 10100 10101 11101 00100 01001 00}

%\ans

\vfil\eject%\end
\rightline{\sevenrm March 26, 2000}

\centerline{\largerbold Answers to the bitstream problems in class} 

\medskip 

{\bf Background assumptions} Our messages in bitstreams will be a
succession of words which will be one of three types (the given
percentage frequencies are approximate):

\medskip 

%\def\cl{$\clubsuit$}

$\bullet$ 50\% of the words are 1010101010. This is 10 bits long,
alternating 1's and 0's. Call it {\bf P}.

\smallskip

%\def\ht{$\heartsuit$}

$\bullet$ 25\% of the words are 1111111. This is 7 bits long, all
1's. Call it {\bf Q}.

\smallskip

$\bullet$ 25\% of the words are 000000. This is 6 bits
long, all 0's. Call it {\bf R}.

\medskip

We'll call bitstreams composed of these words, sentences. The sentence
{\bf R}{\bf Q}{\bf P}{\bf R} is:

\smallskip

\centerline{\tt 00000011111111010101010000000}

\smallskip

Bitstreams will divided into groups of five bits each to make it
easier to refer to parts of them. Then the sentence above is written:


\smallskip

\centerline{\tt 00000 01111 11110 10101 01000 0000}

%\medskip
\bigskip
\hrule\smallskip\hrule
\bigskip

{\bf Problem 1} 

Write the following sentence in terms of {\bf P}, {\bf Q}, and {\bf
R}.

\medskip

{\tt 10101 01010 11111 11101 01010 10000 00010 10101 01011 11111 10101
01010}

\medskip

{\bf Answer to problem 1} 

This is just direct translation and the
answer is {\bf P}{\bf Q}{\bf P}{\bf R}{\bf P}{\bf Q}{\bf P}.

\bigskip
\hrule\smallskip\hrule
\bigskip

{\bf Problem 2} 

Here is a sentence which has been xored with a
pseudorandom bitstream with approximately 10\% 1's. Write the
original sentence in terms of {\bf P}, {\bf Q}, and {\bf R}.

\smallskip
{\tt
11011 11101 01010 10101 00010 10001 01010 00010 00010 10101 01011 11011 
}
\medskip
{\bf Answer to Problem 2} 

This is the pseudorandom bitstream used in the
problem:

\smallskip
\centerline{\tt
00100 00000 00000 00000 01000 00100 00000 10010 00000 00000 00000 00100}
\smallskip

and here's the original bitstream:

\smallskip
\centerline{\tt
11111 11101 01010 10101 01010 10101 01010 10000 00010 10101 01011 11111}
\smallskip

so that the bitstream is {\bf Q}{\bf P}{\bf P}{\bf P}{\bf R}{\bf
P}{\bf Q}. One can guess this (and, really, this is {\it only}\/ a
guess!) by looking at the patterns. The first 7 bits in the bitstream
of the problem statement are {\tt 11011 11} and since every bit there
has a 90\% chance of being correct, it is rather unlikely that this is
a result of xoring with either {\bf P}\ or {\bf R}. For example, if we
had started with {\bf R}, we'd need to change from {\tt 00000 0} to
{\tt 11011 1} and that would mean a total of 5 out of 6 ``bitflips''
-- there's only one chance out of 100,000 (that's $10^5$) of that
happening. If we had started with {\bf P}, we'd need to change from
{\tt 10101 01} to {\tt 11011 11}. The number of bitflips here would be
4. The chance of that occurring is one chance out of 10,000. Compare
that with starting with {\bf Q}, where only one bitflip (one chance of
10) is necessary.

\smallskip

\centerline{$\star\star\star\star\star$}
\smallskip
{\bf Lesson from problem 2} 

In real life, people look {\it very}\/ carefully at the statistics of
the pseudorandom bitstreams that are used. Even small systematic
biases (1\% more 1's than 0's, for example) can be easily exploited by
cryptanalysis. Much more complex statistics than simple counting are
explored. Correlations (relationships between the bits) are
investigated quite closely.


\bigskip
\hrule\smallskip\hrule
\bigskip

{\bf Problem 3} 

The following bitstream is two sentences xored together. Write the
original sentences in terms of {\bf P}, {\bf Q}, and {\bf R} as well
as you can.

\smallskip

{\tt 01010 10111 10101 01000 00000 00101 01000 00101 01001 01010 11110
10101 } 

\medskip

{\bf Answer to problem 3} 

The two bitstreams which were created are 

{\tt 10101 01010 11111 11101 01010 10000 00010 10101 01011 11111 10101
01010 }

which is
{\bf P}{\bf Q}{\bf P}{\bf R}{\bf P}{\bf Q}{\bf P} and 

{\tt 11111 11101 01010 10101 01010 10101 01010 10000 00010 10101 01011
11111 } 

which is {\bf Q}{\bf P}{\bf P}{\bf P}{\bf R}{\bf P}{\bf Q}.

The difference in length and pattern make it fairly easy to learn what
the two bitstreams are. The solutions written above are {\it not}\/
the only possibilities. The sequences {\bf P}{\bf Q}{\bf P}{\bf P}{\bf
R}{\bf Q}{\bf P} and {\bf Q}{\bf P}{\bf P}{\bf R}{\bf P}{\bf P}{\bf Q}
give the same answer. There are also other valid
answers. Cryptanalysis needs some inspired guessing or further
information about either the meaning of the ``language'' or about the
relative frequencies of {\bf P} coming after {\bf Q} versus {\bf Q}
coming after {\bf P}: more statistical information. Such information
is certainly recorded about any language of interest.


\smallskip
\centerline{$\star\star\star\star\star$}
\smallskip

{\bf Lesson from problem 3} 

Many people think that a one-time pad constructed from a common text
(such as a novel or a book of poems or a dictionary) is a good
idea. This example should show that the statistics of a natural
language are so rough (non-random) that natural language should {\it
never}\/ be used as the source of a random bitstream.

\bigskip
\hrule\smallskip\hrule
\bigskip
%\vfil\eject
%\smallskip \centerline{$\star\star\star\star\star$} \bigskip


{\bf Problem 4} 

A pseudorandom bitstream with approximately 50\% 1's and 50\% 0's has
been created. Two \underbar{different} sentences have been xored with
it and the results are shown. Write the original sentences in terms of
{\bf P}, {\bf Q}, and {\bf R} .

\medskip
{\tt
11110 00111 00101 10010 10010 10011 11101 11110 00100 10111 01110 11011 100}
\medskip

{\tt
11110 00111 10000 10010 11000 00110 10111 10100 10101 11101 00100 01001 00}

\medskip
{\bf Answer to problem 4} 

This is the pseudorandom bitstream used in the problem

\smallskip
\centerline{\tt
01011 01101 10000 11000 01101 01100 00010 10100 10000 10111 10001 00011 100}
\smallskip

and following are the two original sentences (in order).
\smallskip
\centerline{\tt
10101 01010 10101 01010 11111 11111 11111 01010 10100 00000 11111
11000 000}
\smallskip
This sentence is {\bf P}{\bf P}{\bf Q}{\bf Q}{\bf P}{\bf R}{\bf Q}{\bf R}.

\smallskip
\centerline{\tt
10101 01010 00000 01010 10101 01010 10101 00000 00101 01010 10101
01010 10}
\smallskip
This sentence is {\bf P}{\bf R}{\bf P}{\bf P}{\bf R}{\bf P}{\bf P}. 
\smallskip
The xor of the two sentences is 

\smallskip
\centerline{\tt
00000 00000 10101 00000 01010 10101 01010 01010 10001 01010 01010
10010 10}
\smallskip

which \underbar{must} be the same as the xor of the two encrypted
sentences. Why?

\medskip
\centerline{\bf Digression on $\oplus$ (the xor symbol)}
\medskip
\quad $\oplus$ is addition mod 2. So the entire definition of $\oplus$
is given by these equations:

\centerline{$0 \oplus 0=0; \quad 0 \oplus 1= 1; \quad 1 \oplus 0= 1; \quad 1
\oplus 1 =0$}

$\oplus$ is used extensively in cryptography because
$a\oplus b \oplus b = a$ for any $a$'s and $b$'s, so we can do the
following:

\smallskip

{\sevenrm \baselineskip=.7\baselineskip 


\line{\hskip .5in
\hbox{\hsize=.6in \vtop{One original\par \centerline{message bit}}}\hskip .18in
\hbox{\hsize=.3in \vtop{Encryption\par \centerline{\qquad using $\scriptstyle b$}}}\hskip .45in
\hbox{\hsize= .6in \vtop{\ \ \ Message\par transmission}}\hskip .6in
\hbox{\hsize=.4in \vtop{Decryption\par \centerline{\ \ \ using
$\scriptstyle b$}}}\hskip .57in 
\hbox{\hsize=.7in \vtop{Original message\par \centerline{\ \ \ bit received.}}}
\hfil} 
}


$$ \overbrace{a}  \longrightarrow \overbrace{a\oplus b = m}
\longrightarrow \overbrace{m \ldots m}\longrightarrow
\overbrace{m\oplus b = a\oplus b \oplus b =a}\longrightarrow \overbrace{a}$$

%\line{\hskip .9in
%\hbox{\hsize=.6in \vtop{One original message bit}}\hskip .1in
%\hbox{\hsize=.3in \vtop{Encryption using $\scriptstyle b$}}\hskip .37in
%\hbox{\hsize= .6in \vtop{\ \ Message\par transmission}}\hskip .2in
%\hbox{\hsize=.3in \vtop{Decryption\par using $\scriptstyle b$}}\hskip .5in
%\hbox{\hsize=.7in \vtop{Original message\par bit received.}}
%\hfil}
%}
%
%$$ a  \longrightarrow a\oplus b = m \longrightarrow m \longrightarrow
%m\oplus b = a\oplus b \oplus b =a $$

\centerline{\bf End of digression on $\oplus$ (the xor symbol)}

\medskip

If $a$ is a bit from the first sentence, $A$ is a corresponding bit
(in the same position) from the
second sentence, and $b$ is the corresponding bit from the bitstream
which encrypts them both, then 
$a \oplus b$ and $A \oplus b$ are bits of the encrypted stream. If
we xor these bits we get:
\smallskip
\centerline{$(a\oplus b) \oplus (A \oplus b) = a \oplus A \oplus b \oplus b = a
\oplus A$}
\smallskip
so $b$ has no influence on what's left. We can just use ideas about
$a$ and $A$ to try to guess about them. In the case of the messages
given, we are lucky (not very, given the statistics of this language!)
that both of the messages begin with {\bf P}. The next pattern in the
xored bitstream is {\tt 10101} which suggests alternating agreement
and disagreement among the bitstreams. Since {\tt 1} means
\underbar{dis}agreement of bitstreams, we examine our dictionary:

\smallskip
\centerline{{\bf P}={\tt 1010101010}\quad  {\bf Q}={\tt 1111111} \quad
{\bf R}={\tt 000000}}
\smallskip

and see that one of the sentences has the word {\bf P}\ and one must
have {\bf R} because they disagree on the first bit of the third group.
Now we continue, really guessing which of the sentences has {\bf P}\
and which has {\bf R}\ and following the consequences. Sometimes the
wrong guess will be made so backtracking will need to be done:
consideration of alternative possibilities.

\smallskip
\centerline{$\star\star\star\star\star$}
\smallskip

{\bf Lesson from problem 4} 

{\it Never}\/ use a pseudorandom bitstream more than
once. Cryptanalysis can rapidly read both of the message streams --
such a situation is sometimes called a ``depth''. There's almost no
protection: a \underbar{one}-time pad should be used exactly once.



\vfil\eject\end


