Cryptography: stream cipher and block cipher


Stream Cipher

A stream cipher is a symmetric key cipher where plaintext digits are combined with a pseudorandom cipher digit stream. In a stream cipher, each plaintext digit is encrypted one at a time with the corresponding digit of the key stream, to give a digit of the cipher text stream.

One time pad

In Cryptography, one time pad is an encryption technique that cannot be cracked, but requires the use of one-time pre-shared key the same size as the message being sent. For OTP, encryption and decryption is defined as:

E(k, m) = k XOR m (Encryption)
D(k, c) = k XOR c (Decryption)

The one time pad is the only example of perfect secrecy, in this technique, brute force is pointless. Here is an example of how to solve a one time pad encryption:

Suppose you are told that the one time pad encryption of the me-
ssage “attack at dawn” is 09e1c5f70a65ac519458e7e53f36 (the pla-
intext letters are encoded as 8-bit ASCII and the givencipherte-
xt is written in hex). What would be the one time pad encryptio-
n of the message “attack at dusk” under the same OTP key?

At first, we know that the message “attack at dawn” convert to “09e1c5f70a65ac519458e7e53f36”, so we assign “attack at dawn” to m1, and “09e1c5f70a65ac519458e7e53f36” to c1. Because c1 is the encrypted result of m1, so

c1 = m1 ⊕ k => k = c1⊕m1

In this problem, m2 = “attack at dawn”, and we know:

c2 = m2 ⊕ k => c2 = m2 ⊕ c1 ⊕ m1

So we can get the the OPT key of message “attack at dusk”. To implement it with the python code is:

def strxor(s1,s2):
return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2))
strxor(strxor("6c73d5240a948c86981bc294814d".decode('hex'), "attack at dawn"), "attack at dusk").encode('hex')

However, it lacks in portability-the key is the same size as the message and convenience- you must never reuse the key. Modern stream ciphers attempt to approximate the one-time pad with a pseudorandom key stream, in OTP with a pseudorandom key, which is smaller than |M|.

Block cipher

Block ciphers use a key to encrypt a fixed-size block of plaintext into a fixed-size block of ciphertext. They are usually more computationally expensive than stream ciphers, but have numerous benefits.

Claude Shannon suggested that all that was required for a strong cipher was repeated substation and permutation. SP-Networks combine a substitution process with a permutation into a single round.

  1. Substitution Boxes: Add confusion by replacing value with other values using a lookup table.
  2. Permutation Boxes: Add diffusion by moving values around from input to output.