hpolzer

Stream cipher

Apr 20th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.81 KB | None | 0 0
  1. /*
  2.     Encrypt a file from stdin to stdout, to run from the command line type:
  3.     encryption key <infile >outfile
  4.     Compile: gcc -ansi -o encryption encryption.c
  5.     KEEP IN MIND THAT THIS CIPHER IS WEAK! Use for educational and
  6.     experimental purposes only!
  7.  
  8.     Copyright (C) <March 09th, 2017> Henning POLZER,
  9.     send comments and error reports to: h underscore polzer at gmx dot de
  10.  
  11.     This program is free software: you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation, either version 3 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23. */
  24.  
  25.  
  26. #include <stdio.h>                      /* getchar, putchar */
  27. #include <stdlib.h>                     /* atoi, (s)rand */
  28. #include <string.h>                     /* strlen */
  29.  
  30.  
  31. int main (int argc, char *argv[])
  32. {
  33.     int c,i,j=0,schl_l,zuf=0;           /* 'c' nicht als char vereinbaren! */
  34.     char *schl=argv[1];
  35.  
  36.     schl_l=strlen (schl);               /* Startwert bilden aus der */
  37.     for (i=0; i<schl_l;i++)             /* Schluessellaenge, dem Wert jedes */
  38.       zuf+=schl_l+schl[i]+i;            /* einzelnen Buchstabens und lfd. Nr. */
  39.     srand (zuf);                        /* Zufallsgen. damit initialisieren */
  40.  
  41.     while ((c=getchar()) != EOF)    {   /* von stdin lesen */
  42.       zuf=rand();                       /* Zufallszahl lesen */
  43.       putchar (c^(zuf%256));            /* Ergebnis nach stdout schreiben */
  44.       srand (schl[j]+zuf);              /* Zufallsgen. neu initialisieren */
  45.       if (j<schl_l) j++; else j=0;
  46.     } /* while */
  47.  
  48.     return 0;
  49. } /* main */
Add Comment
Please, Sign In to add comment