Facebook
From Bulky Plover, 3 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 54
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     if (argc != 2)
  8.     {
  9.         printf("Podano złą liczbę argumentów!");
  10.         return 0;
  11.     }
  12.  
  13.     char haslo[20];
  14.     printf("Podaj hasło (max 20 znaków): ");
  15.     fgets(haslo, sizeof(haslo), stdin);
  16.    
  17.     char tymczasowy[] = "./tmp_XXXXXX";
  18.     mkstemp(tymczasowy);
  19.    
  20.     FILE *file1;
  21.     FILE *file2;
  22.     if (NULL == (file1 = fopen(argv[1], "rb")))
  23.         return 1;
  24.     if (NULL == (file2 = fopen(tymczasowy, "wb")))
  25.         return 1;
  26.  
  27.     int j = 0;
  28.     int znak;
  29.     while ((znak = getc(file1)) != EOF)
  30.     {
  31.         znak ^= haslo[j++ % strlen(haslo) - 1];
  32.         putc(znak, file2);
  33.        
  34.     }
  35.     rename(tymczasowy, argv[1]);
  36.     fclose(file1);
  37.     fclose(file2);
  38. }