Permalink
Browse files

fcrypto

  • Loading branch information...
1 parent 6478fbc commit fa65098a76dcdfd895772bb361c33b51e444184c ftastemur committed Apr 6, 2012
Showing with 56 additions and 0 deletions.
  1. +56 −0 c/file_encrypt.c
View
56 c/file_encrypt.c
@@ -0,0 +1,56 @@
+/* by ftastemur */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define MAX_FILE_NAME_LEN 80
+
+int main(int argc, char **argv)
+{
+ char source_file_name[MAX_FILE_NAME_LEN + 1];
+ char dest_file_name[L_tmpnam];
+ int key, ch;
+ FILE *fsource, *fdest;
+
+ if (argc != 2) {
+ printf("sifrelenecek dosyanin ismini giriniz : ");
+ gets(source_file_name);
+ printf("anahtar degerini giriniz : ");
+ scanf("%d", &key);
+ }
+ else {
+ strcpy(source_file_name, argv[1]);
+ key = atoi(argv[2]);
+ }
+
+ tmpnam(dest_file_name);
+
+ fsource = fopen(source_file_name, "rb");
+ if (fsource == NULL) {
+ fprintf(stderr, "%s dosyasi acilamiyor!\n", source_file_name);
+ exit(EXIT_FAILURE);
+ }
+
+ fdest = fopen(dest_file_name, "wb");
+ if (fdest == NULL) {
+ fprintf(stderr, "%s dosyasi yaratilamiyor!\n", source_file_name);
+ fclose(fsource);
+ exit(EXIT_FAILURE);
+ }
+
+ srand(key);
+
+ while ((ch = fgetc(fsource)) != EOF)
+ fputc(ch ^ rand(), fdest);
+
+ fclose(fsource);
+ fclose(fdest);
+
+ remove(source_file_name);
+ rename(dest_file_name, source_file_name);
+
+ return 0;
+}
+
+

0 comments on commit fa65098

Please sign in to comment.