You are on page 1of 16

GROUP MEMBERS-

STREAM CIPHER 1. KRISHNA K AGRAWAL 19BCY10044


2. ABHINAV PANDEY        19BCY10032
3. UTKARSH VARSHNEY   19BCY10018

This Photo by Unknown author is licensed under CC BY-NC-ND.


INTRODUCTION
• A stream cipher is a method of encrypting text
(to produce ciphertext) in which a cryptographic
key and algorithm are applied to each binary
digit in a data stream, one bit at a time.
• The main alternative method to stream cipher is,
in fact, the block cipher, where a key and
algorithm are applied to blocks of data rather
than individual bits in a stream. 
HISTORY
• The ideas that resulted in modern stream ciphers originated with another
AT&T Bell Labs engineer, Gilbert Vernam (1890 – 1960). In 1917,
Vernam developed a scheme to encrypt teletype transmissions. Unlike
Morse code, which uses symbols of different lengths to substitute for
letters of the alphabet, teletype transmission used what we would today
call a 5-bit code for the letters of the alphabet and certain keyboard
commands. Its use was similar to the way that the 8-bit ASCII code is
used today in computing.
Types
• Synchronous stream ciphers • Self-synchronizing stream ciphers

In a synchronous stream cipher a stream of Another approach uses several of the


pseudorandom digits is generated previous N ciphertext digits to compute
independently of the plaintext and ciphertext
the keystream. Such schemes are known
messages, and then combined with the
as self-synchronizing stream
plaintext (to encrypt) or the ciphertext (to
decrypt).  ciphers, asynchronous stream
ciphers or ciphertext
In the most common form, binary digits are
autokey (CTAK). 
used (bits), and the keystream is combined
with the plaintext using the exclusive • An example of a self-synchronising
or operation (XOR). This is termed a binary stream cipher is a block cipher
additive stream cipher.  in cipher feedback (CFB) mode. 
HOW DOES
STREAM CIPHER
WORK?
• Unlike block ciphers that operate on chunks of
input text, a stream cipher operates on a byte-at-
a-time basis using an input stream.
• Actually, A stream cipher works using two data
streams. The second data stream is the stream of
key data. The key data stream is generated by a
function whose seed is the encryption key.
Example:
PROCESS(ENCRYPTION+DECRYPTION)
• Person A attempts to encrypt a 10-bit message using a stream cipher. The one-time pad, in this case, would also be
at least 10 bits long. This can become cumbersome depending on the size of the message or document they are
attempting to encrypt, however. 
• Cryptographers also refer to the symmetric key used in a stream cipher as a keystream. This is because Person A
could opt to create a pseudo-random cipher digit stream, or keystream, using a key that is smaller than the size of
the plaintext file. Furthermore, to avoid having to create a larger keystream, users can use a cryptographic number
generator to create a larger keystream from a smaller, pseudo-random key. 
• Here, Person A decides to use a 4-bit key to encrypt a 10-bit message. To do that, they must first use an
initialization vector (IV) to generate a random seed value. Placing this seed value into a cryptographic number
generator, Person A can create a pseudo-random keystream that matches the size of their desired plaintext file. 
• The quality of the number generator contributes to the randomness and security of the ciphertext, however. Lower-
end cryptographic number generators can sometimes have patterns that malicious users, or hackers, can identify
and use to decrypt the ciphertext.
• After the user has created the keystream, the stream cipher
combines the keystream with the corresponding digits of the
plaintext using the exclusive-or (XOR) operator. The XOR
operator creates new binary values, which make up the
ciphertext. It generates these values by comparing bits in the
plaintext and the keystream that share the same position. 
• For example, the first bit in Person A's 10-bit message will be
XOR-ed with the first bit of the keystream. If the two digits are
the same, the XOR operator will produce a zero. If the two are
different -- i.e., a combination of 1 and 0 -- the XOR operator
will produce a 1. This is part of what makes stream cipher
encryption so fast. 
• Once each bit of data has been XOR-ed by the stream cipher, it
will produce an unreadable ciphertext message. 
• Decryption of the ciphertext can happen in a manner similar to
how the plaintext encryption occurs. This time, instead of the
data and keystream being XOR-ed, the ciphertext and the
keystream are XOR-ed. 
• Stream ciphers users should not use the same IV more than
once, however, to maximize the security of this process. 
Diagram of Stream
Cipher 
Code 
• #include <iostream>
• #include <string>
• #include<vector>
• using namespace std;

• vector<int> permute(vector<int>, vector<int>);


• string encrypt(vector<int>s , vector<int> t, string p);
• string decrypt(vector<int>s, vector<int> t, string p);

• int main() {

• string plaintext = "cryptology";


• string plaintext2 = "RC4";
• vector<int> S(256); //Fill with for loop
• vector<int> T(256); // Fill with key 

• int key[] = { 1,2,3,6 };


• int key2[] = { 5,7,8,9 };
Code Continues..
// Initiliaze the S and T vectors cout << "Decrypted Message:  " << decrypt(S, T, p)
int tmp = 0; << endl << endl;
for (int i = 0; i < 256;i++) { //Init S and T
tmp = 0;
S[i] = i; for (int i = 0; i < 256;i++) {
T[i] = key[( i % (sizeof(key)/sizeof(*key)) )]; S[i] = i;
} T[i] = key2[(i % (sizeof(key) / sizeof(*key)))];
S = permute(S, T); }
for (int i = 0; i < 256 ;i++) { S = permute(S, T);
cout << S[i] << " ";  for (int i = 0; i < 256;i++) {
if ((i + 1) % 16 == 0) cout << S[i] << " ";
if ((i + 1) % 16 == 0)
cout << endl; cout << endl;
} }
cout << endl;
string p = encrypt(S, T, plaintext); cout << endl;
cout << "Message: " << plaintext << endl; p = encrypt(S, T, plaintext2);
cout << "Encrypted Message: " << " " << p << endl; cout << "Message: " << plaintext2 << endl;
cout << "Encrypted Message: " << p << endl;
cout << "Decrypted Message: "<<decrypt(S, T, p)
<< endl << endl;
Code Still Continues...
 system("pause"); int * plain = new int[p.length()];
return 0;
string plain_T;
}

string decrypt(vector<int>s, vector<int> t, string p) { for (int r = 0; r < p.length(); r++) {


int i = 0;
i = (i + 1) % 256;
j = (j + s[i]) % 256;
int j = 0;
// swap section
int tmp = 0;
b = s[i];
int k = 0; s[i] = s[j];
s[j] = b;

//temp variables tmp = (s[i] + s[j]) % 256;


k = s[tmp];
int b; c = ((int)p[r] ^ k); // cast the p string as and int then xor with k
int c;
Code Code Code...
plain[r] = c;
int * cipher = new int [p.length()];

plain_T += (char)plain[r]; // Cast plaintext int array as a char string cipher_T;

cout << "Keys Generated for plaintext: ";


}
return plain_T; for (int r = 0; r < p.length(); r++) {
}
i = (i + 1) % 256;
string encrypt(vector<int>s, vector<int> t, string p) { j = (j + s[i]) % 256;

int i = 0;
// swap section
int j = 0; b = s[i];
int tmp = 0; 
int k = 0; s[i] = s[j];
s[j] = b;

//Temp variables
int b;  tmp = (s[i] + s[j]) % 256;
int c;
k = s[tmp];
It's Code Mania! 
cout << k << " ";

c = ((int)p[r] ^ k); //Cast p char as an int then xor with k

cipher[r] = c; 

cipher_T += (char)cipher[r];  //cast int as char then append to string

cout << endl;

return cipher_T;

vector<int> permute(vector<int> s, vector<int> t) {

int j = 0;

int tmp;

for (int i = 0; i< 256; i++) {

j = (j + s[i] + t[i]) % 256;

tmp = s[i];

s[i] = s[j];

s[j] = tmp;

return s;

}
POINTS TO REMEMBER
 Stream Cipher follows the sequence of pseudorandom number stream.
 One of the benefits of following stream cipher is to make cryptanalysis more difficult, so
the number of bits chosen in the Keystream must be long in order to make cryptanalysis
more difficult.
 By making the key more longer it is also safe against brute force attacks.
 The longer the key the stronger security is achieved, preventing any attack.
 Keystreamcan be designed more efficiently by including more number of 1s and 0s, for
making cryptanalysis more difficult.
 Considerable benefit of a stream cipher is, it requires few lines of code compared to block
cipher.
THANK YOU

You might also like