Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
2
Indexable
Never
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void CSR_encrypt(char msg[])
{
 char enc[25], letters[]="abcdefghijklmnopqrstuvwxyz";
 int key, i, j, k;

 printf("key: ");
 scanf("%i", &key);

 for(i=0; i<strlen(msg); i++)
    for(j=0; j<strlen(letters); j++)
        if(msg[i]==letters[j]) {
            if((j+key)<strlen(letters))
                enc[i]=letters[j+key];
            else {
                k=(j+key)-strlen(letters);
                enc[i]=letters[k];
            }
        }

 printf("enc: ");
 for(i=0; i<strlen(msg); i++)
    printf("%c", enc[i]);
 printf("\n");
}

CSR_decrypt() { printf("decrypt function\n"); }
main(int argc, char *argv[])
{
 char *prg=argv[0];
 char *opt=argv[1];
 char *msg=argv[2];
 if(argc==1) {
 fprintf(stderr, "%s: no option and massage\n", prg);
 exit(3);
 }
 if(argc==2) {
 fprintf(stderr, "%s: no option or message\n", prg);
 exit(2);
 }
 if(argc==3) {
 if(strcmp(opt,"-Ecsr")==0)
 CSR_encrypt(msg);
 else if(strcmp(opt,"-Dcsr")==0)
 CSR_decrypt();
 else {
 fprintf(stderr, "%s: illegal option: %s\n", prg, opt);
 exit(1);
 }
 }
 exit(0);
}