// XOR cipher with files

#include <iostream>
#include <fstream>

int main(int argc, char** argv) {
  char cci, ccp, cco;

  if (argc != 4) {
    std::fprintf(stderr, "Syntax: %s inputFile patternFile outputFile\n", argv[0]);
    return 1;
  }

  std::ifstream fin(argv[1], std::ios::in | std::ios::binary);
  std::ifstream finp(argv[2], std::ios::in | std::ios::binary);
  std::ofstream fout(argv[3], std::ios::out | std::ios::binary);

  while (fin.get(cci)) {
    if (finp.get(ccp)) {
      cco = cci ^ ccp;
      fout.put(cco);
    } else {
      finp.clear();
      finp.seekg(0);
      finp.get(ccp);
      cco = cci ^ ccp;
      fout.put(cco);
    }
  }

  fin.close();
  finp.close();
  fout.close();

  return 0;
}
      

// Generated by xformulas.net on 20190910_085536