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