Upload files to "/"
kode
This commit is contained in:
55
xorcrypt.c
Normal file
55
xorcrypt.c
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user