Shortest 8-bit xor cipher 8-bit XOR encryption takes a single byte and XORs every byte in the file by that byte. Here is a reference program in C++:

/*xorcipher.cpp
 *Encrypts a file using 8-bit xor encrytpion
 */

#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;stdlib.h&gt;
using namespace std;

int main(int argc, char** argv){
   ifstream* in = NULL;
   ofstream* out = NULL;

   if(argc &lt; 3){
      cerr &lt;&lt; "Usage: xor &lt;key&gt; &lt;filename...&gt;" &lt;&lt; endl;
      exit(1);
   }

   int key = atoi(argv[1]);

   for(int x = 2; x &lt; argc; x++){
      in = new ifstream(argv[x], ios::binary);
      if(!in-&gt;good()){
         cerr &lt;&lt; "Error reading from " &lt;&lt; argv[x] &lt;&lt; endl;
         exit(1);
      }

      //Get file size
      in-&gt;seekg(0, ios::end);
      int size = in-&gt;tellg();
      in-&gt;seekg(0, ios::beg);

      //Allocate memory
      int* data = new int[size];

      int c = 0;
      for(int y = 0; (c = in-&gt;get()) != EOF; y++)
         data[y] = c ^ key;

      in-&gt;close();
      delete in;
      in = NULL;

      out = new ofstream(argv[x], ios::binary);
      if(!out-&gt;good()){
         cerr &lt;&lt; "Error writing to " &lt;&lt; argv[x] &lt;&lt; endl;
         exit(1);
      }

      for(int y = 0; y &lt; size; y++)
         out-&gt;put(data[y]);

      out-&gt;flush();
      out-&gt;close();
      delete out;
      out = NULL;

      delete[] data;
      data = NULL;
   }
   cout &lt;&lt; "Operation complete" &lt;&lt; endl;

   return 0;
}


The shortest answer (whitespace doesn't count) that produces the same end result will be selected. It does not have to store everything in memory at once or open and close every file multiple times. It can do anything as long as a file encrypted with the reference program can be decrypted with the answer, and vice versa.


Edit: The above program is not a specification. The only requirement is that answers should be able to decrypt a file encrypted with the above program, and the above program should be able to decrypt a file encrypted with the answer. I'm sorry if that was unclear.

The above program can be compiled with:

g++ xorcipher.cpp -o ~/bin/xor


It can be run like this:

xor &lt;key&gt; &lt;filename...&gt;


For example, if the key is 42 and the file is alpha.txt, you would use:

xor 42 alpha.txt
Brainfuck - 269

,&gt;,[&lt;[&gt;&gt;+&gt;+&lt;&lt;&lt;-]&gt;&gt;&gt;[&lt;&lt;&lt;+&gt;&gt;&gt;-]&gt;&gt;&gt;++++++++[-&lt;&lt;&lt;&lt;&lt;[-&gt;&gt;+&lt;&lt;[-&gt;&gt;-&gt;+&lt;]&gt;&gt;[-&gt;&gt;&gt;
&gt;+&lt;&lt;]&lt;&lt;&lt;&lt;]&gt;&gt;&gt;[-&lt;&lt;&lt;+&gt;&gt;&gt;]&lt;&lt;[-&gt;+&lt;[-&gt;-&gt;+&gt;&gt;&gt;&gt;&gt;]&gt;[-&gt;&gt;&gt;&gt;&gt;+&gt;&gt;]&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;]&gt;&gt;[-&lt;&lt;+
&gt;&gt;]&gt;&gt;&gt;[-&gt;&gt;+&lt;&lt;]&gt;[&gt;[-&lt;-&gt;]&lt;[-&gt;+&lt;]]&gt;[[-]&lt;&lt;&lt;[-&gt;+&gt;-&lt;&lt;]&gt;[-&lt;+&gt;]+&gt;+++++++[-&lt;[-&gt;
&gt;++&lt;&lt;]&gt;&gt;[-&lt;&lt;+&gt;&gt;]&lt;]&lt;[-&gt;&gt;&gt;&gt;+&lt;&lt;&lt;&lt;]&gt;&gt;]&lt;&lt;&lt;]&gt;&gt;&gt;&gt;&gt;.[-]&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;,]