07.07.2023 Views

Implementing-cryptography-using-python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2 ■ Cryptographic Protocols and Perfect Secrecy 51

a perfectly secure Shannon cipher. That is, the perfectly secure Shannon cipher

ε has produced a ciphertext that has equal probability of being any message, i.e.,

the ciphertext c gives no information about the plaintext m.

We will explore perfect security more as we explore the one-time pad in the

next section.

One-Time Pad

Perfect secrecy is the concept that given a ciphertext (an encrypted message) from

a cipher or perfectly secure encryption system, nothing will be revealed about

the plaintext (unencrypted message) by the ciphertext.

A perfectly secret cipher has a couple of other equivalent properties:

■■

There is a key that encrypts every possible plaintext to every possible

ciphertext (perfect key ambiguity). However, this is true only if the keys

used are the same size as the messages.

■■

Even if given a choice of two plaintexts, one the real one, for a ciphertext,

you cannot distinguish which plaintext is the real one (perfect message

indistinguishability).

What perfect secrecy means in practice is that no amount of computation

applied to the ciphertext will give you any advantage in knowing anything

about the plaintext or key. This is obviously a desirable property of a cipher,

and perfectly secret ciphers do exist. For example, a one-time pad (OTP) is a

perfectly secret cipher.

When you examine the OTP, you may decide that it is the basis of modern

cryptography or you may determine it does not accomplish what we need.

Still, it is important that you understand the scheme and its subtleties. In this

section, you will gain a formal description of the algorithm and will explore

the OTP from Python; the goal is to show that it can be broken when used in

a repetitive scenario.

XOR, AND, and OR

The bitwise operators work on bits and perform bit-by-bit operations. Assume

a = 60 and b = 13. The binary format of a and b will be as follows:

a = 0011 1100

b = 0000 1101

Table 2.2 explains each bitwise operator and gives an example.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!