From ed84056aa9136acc95046d1c506b3724b767e302 Mon Sep 17 00:00:00 2001 From: disu1950 Date: Sat, 15 Nov 2025 06:20:29 +0000 Subject: [PATCH] Upload files to "/" kode --- xorcrypt.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 xorcrypt.c diff --git a/xorcrypt.c b/xorcrypt.c new file mode 100644 index 0000000..654dbd6 --- /dev/null +++ b/xorcrypt.c @@ -0,0 +1,55 @@ +#include + +char getbyte (FILE *fp) +{ + char byte; + fread (&byte, 1, 1, fp); + return byte; +} + +void putbyte (FILE *fp, char byte) +{ + fwrite (&byte, 1, 1, fp); +} + +void xorfile (FILE *ifp, FILE *ofp, char key[]) +{ + unsigned kpos = 0; + char byte; + for (;;) + { + byte = getbyte (ifp); + if (feof (ifp)) + break; + else + { + if (key[kpos]) + kpos++; + else + kpos = 0; + putbyte (ofp, (byte ^ key[kpos])); + } + } +} + +int main (int argc, char *argv[]) +{ + FILE *ifp, *ofp; + char *key = argv[3]; + if (argc <= 3) + { + puts ("XORCRYPT infile outfile key"); + puts (" Encrypts/Decrypts a file using XOR operation."); + puts (" Programmed by DISU \"1950\" DISU1950 in 2077."); + return 1; + } + ifp = fopen (argv[1], "rb"); + ofp = fopen (argv[2], "wb"); + if (ifp && ofp) + { + xorfile (ifp, ofp, key); + return 0; + } + puts ("Access was denied."); + return 1; +} \ No newline at end of file