In: Computer Science
List the primitive operations used in the RC4 stream cipher algorithm for
A) Key Stream Generation
B) Bit Stream Encryption
A)RC4 is a stream cipher and variable length key algorithm. This calculation encodes each byte in turn (or bigger units on a period). A key information is pseudorandom bit generator that creates a stream 8-bit number that is erratic without information on input key, The yield of the generator is called key-stream, is joined each byte in turn with the plaintext stream cipher utilizing X-OR activity.
Example:
RC4 Encryption
10011000 ? 01010000=11001000
RC4 Decryption
11001000 ? 01010000=10011000
11001000 ? 01010000 = 10011000
Key-Generation Algorithm –A variable-length key from 1 to 256 byte is utilized to introduce a 256-byte state vector S, with components S[0] to S[255]. For encryption and unscrambling, a byte k is produced from S by choosing one of the 255 entries in a methodical manner, at that point the sections in S are permuted once more.
Key-Scheduling Algorithm:
Iinitialization: The sections of S are set equivalent to the qualities from 0 to 255 in climbing request, a transitory vector T, is made.
On the off chance that the length of the key k is 256 bytes, at that point k is allocated to T. Something else, for a key with length(k-len) bytes, the main k-len components of T as replicated from K and afterward K is rehashed the same number of times as important to fill T. The thought is represented as follow:
for
i = 0 to 255 do S[i] = i;
T[i] = K[i mod k - len];
we use T to produce the initial permutation of S. Starting with
S[0] to S[255], and for each S[i] algorithm swap it with another
byte in S according to a scheme dictated by T[i], but S will still
contain values from 0 to 255 :j = 0;
for
i = 0 to 255 do
{
j = (j + S[i] + T[i])mod 256;
Swap(S[i], S[j]);
}
Pseudo random generation algorithm (Stream
Generation):
When the vector S is introduced, the info key won't be utilized. In
this progression, for each S[i] calculation trade it with another
byte in S as indicated by a plan directed by the current
arrangement of S. In the wake of coming to S[255] the procedure
keeps, beginning from S[0] once more
i, j = 0;
while (true)
i = (i + 1)mod 256;
j = (j + S[i])mod 256;
Swap(S[i], S[j]);
t = (S[i] + S[j])mod 256;
k = S[t];
BIT STREAM Encrypt using X-Or():XOR Encryption is
an encryption technique used to scramble information and is
difficult to break by animal power strategy, i.e creating arbitrary
encryption keys to coordinate with the right one.
void encryptDecrypt(char inpString[])
{
// Define XOR key
// Any character value will work
char xorKey = 'P';
// calculate length of input string
int len = strlen(inpString);
// perform XOR operation of key
// with every caracter in string
for (int i = 0; i < len; i++)
{
inpString[i] = inpString[i] ^
xorKey;
printf("%c",inpString[i]);
}
}
// Driver program to test above function
int main()
{
char sampleString[] = "GeeksforGeeks";
// Encrypt the string
printf("Encrypted String: ");
encryptDecrypt(sampleString);
printf("\n");
// Decrypt the string
printf("Decrypted String: ");
encryptDecrypt(sampleString);
return 0;
}