Skip to content

Instantly share code, notes, and snippets.

@DreamVB
Created July 17, 2018 21:01
Show Gist options
  • Select an option

  • Save DreamVB/9e34d7b56a3d1821a4e7834acab4ffdf to your computer and use it in GitHub Desktop.

Select an option

Save DreamVB/9e34d7b56a3d1821a4e7834acab4ffdf to your computer and use it in GitHub Desktop.
//A small simple file crypting tool in C++
//By Ben Jones Hope you like it.
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
FILE *fin = NULL;
char *pws;
int idx = 0, i = 0;
FILE *fout = NULL;
char c = '\0';
if (argc < 3){
std::cout << "Incorrect number of parameters." << endl;
std::cout << "Syntax InputFile OutputFile Password" << endl;
return 1;
}
//Open source file.
fin = fopen(argv[1], "rb");
if (fin == NULL){
std::cout << "Error opening input filename." << endl;
return 2;
}
//Open output file for writing.
fout = fopen(argv[2], "wb");
//Check if can write to output.
if (fout == NULL){
std::cout << "Error writing output file." << endl;
fclose(fin);
return 2;
}
pws = new char[strlen(argv[3])];
//Copy password from argv[3] to pws
strcpy(pws, argv[3]);
while (!feof(fin)){
//Encrypt char.
c = getc(fin) ^ pws[idx];
//Get password char
idx = (i % strlen(pws));
//INC counter
i++;
//Check if not end of file.
if (!feof(fin)){
//Write char to output file.
putc(c, fout);
}
}
//Close output file.
fclose(fout);
//Close input file.
fclose(fin);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment