12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #include <iostream>
- using namespace std;
- int main() {
-
- int key_size,plain_text_size,N=8,l=8,k=0;
- cout<<"Enter the size of key\n";
- cin>>key_size;
-
- cout<<"Enter the size of plain text\n";
- cin>>plain_text_size;
-
- int i,j=0,key[key_size],plain_text[plain_text_size],S[N],Z[key_size],cipher_text[plain_text_size];
-
- cout<<"Enter the key\n";
-
- for(i=0;i<key_size;i++)
- cin>>key[i];
-
- cout<<"Enter the plain text\n";
-
- for(i=0;i<plain_text_size;i++)
- cin>>plain_text[i];
- //KSA
- for(i=0;i<N;i++)
- S[i]=i;
-
- for(i=0;i<N;i++)
- {
- j=(j+S[i]+(key[i%key_size]))%l;
-
- S[i]=S[i]+S[j];
- S[j]=S[i]-S[j];
- S[i]=S[i]-S[j];
-
- }
-
- i=0;j=0;
-
- //PRGA
- for(k=0;i<key_size;k++)
- {
- i++;
- j=(j+S[i])%l;
- int temp;
- temp=S[i];
- S[i]=S[j];
- S[j]=temp;
-
- Z[k]=S[(S[i]+S[j])%l];
-
- cipher_text[k]=plain_text[k] ^ Z[k];
-
-
-
- }
-
- cout<<"Cipher Text is ";
-
- for(i=0;i<plain_text_size;i++)
- cout<<cipher_text[i];
-
-
- cout<<endl;
- return 0;
- }
- /*
- OUTPUT:-
-
- Enter the size of key
- 4
- Enter the size of plain text
- 4
- Enter the key
- 1 2 3 6
- Enter the plain text
- 1 2 2 2
- Cipher Text is 4323
-
- */
|