【C/C++】XOR
本帖最后由 ~风介~ 于 2015-5-23 23:46 编辑C Code: /* Usage: crypto key input_file output_file */
#include <stdio.h>
int main (int argc, char *argv[])
{
FILE *fi, *fo;
char *cp;
int c;
if ((cp = argv) && *cp != '\0')
{
if ((fi = fopen(argv, "rb")) != NULL)
{
if ((fo = fopen(argv, "wb")) != NULL)
{
while ((c = getc(fi)) != EOF)
{
if (!*cp)
cp = argv;
c ^= *(cp++);
putc(c,fo);
}
fclose(fo);
}
fclose(fi);
}
}
return 0;
}
C++ Code: /* Usage: crypto key input_file output_file */
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc,char *argv[])
{
ifstream fin;
ofstream fout;
char ch;
char *cp;
fin.open(argv,ios_base::binary|ios_base::in);
fout.open(argv,ios_base::binary|ios_base::out);
if ((cp = argv) && *cp != '\0')
{
while(!fin.eof())
{
if (!*cp)
cp = argv;
fin.get(ch);
ch ^= *(cp++);
fout.put(ch);
}
}
fin.close();
fout.close();
return 0;
}
Screenshot:
C++编程小组 {:9_241:}
页:
[1]