Then, perform XOR between the keystream generated and the plain text for encryption.
Follow the same procedure as above for decryption, taking cipher text in place of plain text everywhere.
Below is the implementation of the above approach with a detailed output of all the important steps involved:
Output: Plain text : 001010010010
Key : 101001000001
n : 3
S : [0, 1, 2, 3, 4, 5, 6, 7]
Plain text ( in array form ): [1, 2, 2, 2]
Key list : [5, 1, 0, 1, 5, 1, 0, 1]
KSA iterations :
0 [5, 1, 2, 3, 4, 0, 6, 7]
1 [5, 7, 2, 3, 4, 0, 6, 1]
2 [5, 2, 7, 3, 4, 0, 6, 1]
3 [5, 2, 7, 0, 4, 3, 6, 1]
4 [5, 2, 7, 0, 6, 3, 4, 1]
5 [5, 2, 3, 0, 6, 7, 4, 1]
6 [5, 2, 3, 0, 6, 7, 4, 1]
7 [1, 2, 3, 0, 6, 7, 4, 5]
The initial permutation array is : [1, 2, 3, 0, 6, 7, 4, 5]
PGRA iterations :
0 [1, 3, 2, 0, 6, 7, 4, 5]
1 [1, 3, 6, 0, 2, 7, 4, 5]
2 [1, 3, 6, 2, 0, 7, 4, 5]
3 [1, 3, 6, 2, 0, 7, 4, 5]
Key stream : [7, 1, 6, 1]
Cipher text : 110011100011
---------------------------------------------------------
KSA iterations :
0 [5, 1, 2, 3, 4, 0, 6, 7]
1 [5, 7, 2, 3, 4, 0, 6, 1]
2 [5, 2, 7, 3, 4, 0, 6, 1]
3 [5, 2, 7, 0, 4, 3, 6, 1]
4 [5, 2, 7, 0, 6, 3, 4, 1]
5 [5, 2, 3, 0, 6, 7, 4, 1]
6 [5, 2, 3, 0, 6, 7, 4, 1]
7 [1, 2, 3, 0, 6, 7, 4, 5]
The initial permutation array is : [1, 2, 3, 0, 6, 7, 4, 5]
Key stream : [7, 1, 6, 1]
PGRA iterations :
0 [1, 3, 2, 0, 6, 7, 4, 5]
1 [1, 3, 6, 0, 2, 7, 4, 5]
2 [1, 3, 6, 2, 0, 7, 4, 5]
3 [1, 3, 6, 2, 0, 7, 4, 5]
Decrypted text : 001010010010