Простой шифровальщик файлов

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by GrAmOzEkA, 18 Feb 2019.

  1. GrAmOzEkA

    GrAmOzEkA Elder - Старейшина

    Joined:
    25 Jun 2006
    Messages:
    240
    Likes Received:
    76
    Reputations:
    29
    Написан на C:
    Code:
    #include <stdio.h>
    
    main(int  argc, char *argv[])
    {
     
      //char key[100],fname[100],ename[100];
      unsigned char key[100],fname[100],ename[100];
      FILE *fpi,*fpo,*fopen();
      int kkk[100];
      int i,j,k,c,p,pw_len,fn_len;
    
      printf("\n  ** File encryption/decryption program **\n\n");
      printf("  This program will take a password and filename ending in .E\n");
      printf("  and will decrypt the file to a file with the .E suffix removed.\n");
      printf("  If given a filename not ending in .E it will encrypt the file.\n");
    
      if(argc == 1)
        {
          printf("\nEnter the password: ");
          fgets(key,100,stdin);
          // Need to strip off the EOL
          pw_len=strlen(key);
          key[pw_len-1]='\0';
    
          printf("\nEnter the filename: ");
          fgets(fname,100,stdin);
          fn_len=strlen(fname);
          fname[fn_len-1]='\0';
        }
      else if(argc == 3)
        {
          strcpy(key,argv[1]);
          strcpy(fname,argv[2]);
        }
      else
        {
          printf("\n  ** Error!: Usage is %s <password> <filename>\n", argv[0]);
          exit(1);
        }
    
      pw_len=strlen(key)-1;
      for(i=0;i<pw_len;i++)
        {
          kkk[i]=(int)key[i];
        }
    
      fn_len=strlen(fname);
     
      if (fname[fn_len-2]=='.' && fname[fn_len-1]=='E')
        // Decrypt mode
        {
          //strncpy(ename,fname,(fn_len-3));
          strcpy(ename,fname);
          ename[fn_len-2]='\0';
          printf("\nThe output file will be named: %s\n",ename);
        }
      else{
        //Encrypt mode
        strncpy(ename,fname,fn_len);
        ename[fn_len]='.';
        ename[fn_len+1]='E';
        ename[fn_len+2]='\0';
        printf("\nThe output file will be named: %s\n",ename);
      }
     
    
      if((fpi=fopen(fname,"r"))==NULL)
        {
          printf("\nError - file %s not found",fname);
          exit(1);
        }
      if((fpo=fopen(ename,"w"))==NULL)
        {
          printf("\nError - file %s not opened",ename);
          exit(1);
        }
    
      j=0;
     
      while((c = getc(fpi)) != EOF)
        {
          if(j == pw_len) j=0;
          p=c^kkk[j];
          putc(p,fpo);
          j++;
        }
    
    }
    Бинарники Win/Linux и исходник: https://yadi.sk/d/fyGGv2FM1ZCy5Q
    Неплохо было написать еще и брут для него.
     
    #1 GrAmOzEkA, 18 Feb 2019
    Last edited: 18 Feb 2019
    Simonoff likes this.
  2. pravdaru

    pravdaru Member

    Joined:
    5 Dec 2015
    Messages:
    176
    Likes Received:
    45
    Reputations:
    0
    Чем BestCrypt плох? Или TrueCrypt?
     
Loading...