Brief History about Cryptography:
cryptography or cryptology is very old science it’s has been used since Ancient Greek used cryptography to secure communication in presence of third party, from Wikipediacryptography is about constructing and analyzing protocols that prevent third parties or the public from reading private messages; various aspects in information security such as data confidentiality, data integrity, authentication, and non-repudiation are central to modern cryptography.
I’ll write several parts on Cryptography explaining the modern cryptography and the modern attacks on them, you can find the programming part of Cryptography in the coding section under Cryptography as I’ll put the important library and we’ll be doing a hands on project so you can apply your knowledge as we going through.
In part 1 I’ll discuss what stream ciphers are, how secure they are and what are the most common algorithm for stream ciphers.
Let’s start our discussion by talking about simple stream cipher:
the most simple way stream cipher to use stream cipher for encryption and decryption as by using XOR function.
Before we take our example we have to declare some notations M for message, K for key, C for ciphertext, E is a Encryption function, D is a Decryption function.
Example 1.1: consider the case that you have M and K as stream of bits, M = 1101 1100 , K = 1110 0011 . So our Encryption function will be something like this, C_i = M_i XOR K_i where i corresponds to the i’th bit and for i < n-1 so we get our ciphertext C = 0011 1111. In Decryption we reverse the process we take the ciphertext and XOR with the key M_i = C_i XOR K_i where i corresponds to the i’th bit and for i < n-1 so we get our ciphertext M= 1101 1100.
Now we have a good idea about how simple stream cipher can work, If you are asking now how we get the Key you are so smart let’s start discussing Random Number Generators we have two types of Random Number Generators:
- Truly Random Number Generators
- Pseudo-random generators
Truly Random Number Generators
Truly Random Number Generators(TRNG) are characterized that there output can’t be reproduced, for instance if someone flips a coin 100 times and record the resulting sequence in bits it’s impossible for someone else to generate the same 100 bit sequence, TRNG are based on physical process
Pseudorandom number generator (PRNG) is efficient, deterministic algorithm let’s denote it by G that is given seed as input and computes an output r, the seed comes from finite seed space and the out r belongs to a finite output space R,
if s is chosen at random from S and r is chosen at random from R, then no efficient adversary can efectively tell the difference between G(s) and r: the two are computationally indistinguishable, Often (PRNG) are computed recursively here’s a good link from Wikipedia describing how it works.
One-Time Pad (OTP)
OTP is stream cipher where:
- the key stream is derived from TRNG
- Each key is used only once
The big draw back in OTP system is that the key has to be long as the message, it easy to see that OTP is unconditionally secure which means it cannot be broken even with infinite computational resources. because we are using TRNG key.
Well that’s it for the part in the next Part we will continue our talk about stream ciphers, please if you have any question or idea to improve my write-up feel free to e-mail me on firstname.lastname@example.org