Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string.h>
- int generate_mask(int len_c,unsigned char *mask)
- {
- srand (time(NULL));
- int i;
- for(i=0;i<len_c;++i)
- mask[i]=rand()% 255 + 1; // randomn key between 1 and 255, extented ascii
- mask[len_c]='\0';
- return 0;
- }
- int generate_encryption(unsigned char *cipher,unsigned char *mask,unsigned char *crypted,int len_c)
- {
- int i;
- for(i=0;i<len_c;++i)
- {
- if( (mask[i]+cipher[i]) > 255 ) // is the result superior to the table ?
- crypted[i]=(mask[i]+cipher[i]) % 255; // if yes, we make a modulo
- else
- crypted[i]=mask[i]+cipher[i];
- }
- crypted[len_c]='\0';
- return 0;
- }
- int main(int argc, char *argv[])
- {
- if(argc == 2)
- {
- int len_c=strlen(argv[1]);
- unsigned char *mask=(unsigned char *)malloc(sizeof(char)*len_c+1);
- unsigned char *crypted=(unsigned char *)malloc(sizeof(char)*len_c+1);
- generate_mask(len_c,mask);
- generate_encryption((unsigned char *)argv[1],mask,crypted,len_c);
- printf("Message: %s\n Mask: %s\n Crypted: %s\n",argv[1],mask,crypted);
- free(mask);
- free(crypted);
- }
- else
- fprintf(stderr,"Usage: ./<executable> <text to encrypt>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement