Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void keygenerate(char *input,char *key,char *output){
- int k[256];
- for(int i=0;i<255;i++){
- s[i]=i;
- k[i]=key[i % keylen(key)];
- }
- int j=0;
- for(i=0;i<255;i++){
- j=(j+s[i]+k[i]) % 256;
- swap(s[i],s[j]);
- }
- int temp1= strlen(input)+1;
- i=j=0;
- for(int temp2=0;temp2<temp1;temp2++){
- i=(i+1) % 256;
- j=(j+s[i])%256;
- swap(s[i],s[j]);
- t=(s[i]+s[j])%256;
- if(s[t]==input[temp2])
- temp1[temp2]=input[temp2];
- else
- temp1[temp2]=s[t]^input[temp2];
- }
- temp1[temp2]='/0';
- for(temp2=0;temp2<input;temp2++)
- output[temp2]=temp1[temp2];
- delete temp1;
- }
- //c=m XOR s[t];
- int main(){
- char *message;
- char *encryption;
- char *decryption;
- char *k;
- message="Network security assignment";
- k="asd";
- keygenerate(messaage,k,encryption);
- keygenerate(encrypted,k,decryption);
- cout<<"Plain text:"<<message;
- cout<<"key:"<<k;
- cout<<"Encrypted & Decrypted form" << excryption <<","<<decryption;
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement