You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3.8 KiB

Xit - XOR It

Xit is a Python program that applies XOR to files. It's not designed to be used for cryptographic stuff, unless you know what you're doing or you want to hide from your little sister. Xit processes files in the memory and is not designed to treat huge data.


All the current cryptosystem can be broken. It's just a question of (somewhat huge) time. Indeed, it actually exists an unbreakable cryptosystem. It's called the One-time pad (OTP). But it needs:

  • a shared key:
  • which is as long as the clear text,
  • which is to be used only once,
  • which is truly random.

While the randomness is pretty good, it's hard to distribute a key as long as the clear text. Because a key is usable only once, one must generate a random key for each data. But the real issue is the key distribution. That's why modern cryptosystems are theorically weaker but useful.

So, why? In some cases, it's possible to use the OTP in special situations, such as the red hotline. Someone brings the keys from the Russian side to the USA side, and vice-versa... The program is also made to understand the underlying principles and play a bit with it.

Use cases

Create random files

xit ^ one two three --size 1M

The files one, two, and three are random files.

Single communication

Mister A wants to communicate a secret to Miss B, in file 'clear.txt'. Fortunately, two people can carry messages by two very different ways. So :

xit clear.txt ^ a.xor b.xor

The file 'clear.txt' is split into two files 'a.xor' and 'b.xor'. A random key as long as the clear text is xored along with the clear text. Then you got the xored text and the key itself. Which is the key, which is then encrypted text? It's shuffled! So, the people carry the xor files to Miss B, who does:

xit a.xor b.xor ^ clear.txt

The clear.txt file now contains the clear text. Getting the 'a.xor' and 'b.xor' alone won't help to decrypt the message. Of course, with both file it's easy to xor them back.

Multi channels communication

xit clear.txt ^ a b c d e

splits a clear text into five chuncks.

xit a b c d e ^ clear.txt

way back!

Multi steps communication

xit clear.txt ^ a b c
xit a b c ^ x y        # the keys a,b,c turned into keys x,y!
xit x y ^ clear.txt

Can be useful to reduce three keys to two.

Split to many files

xit clear.txt ^ chunk-{10}.txt  # Ten files with they own SHA1 fingerprint.
xit chunk* ^ clear.txt

Split to many files several times

xit clear.txt ^ chunk-a-{10}.txt chunk-b-{15}.txt   # Two groups, each of them giving 'clear.txt' back.
xit chunk-a-* ^ clear.txt
xit chunk-b-* ^ clear.txt

Split to many files several times and common keys

xit clear.txt ^ _textkey_ chunk-a-{10}.txt chunk-b-{15}.txt   # _textkey_ is a text key
xit chunk-a-* _textkey_ ^ clear.txt
xit chunk-b-* _textkey_ ^ clear.txt

Two sets of chunks but each of them needs the textkey (without the underscores).

Three people, but only two of them to decrypt

mkdir a b c
xit clear.txt ^ a/chunk-ab.txt b/chunk-ba.txt
xit clear.txt ^ a/chunk-ac.txt c/chunk-ca.txt
xit clear.txt ^ b/chunk-bc.txt c/chunk-cb.txt

# A, B, and C cannot do anything alone, but...

# A and B share their chunks:
xit a/chunk-ab.txt b/chunk-ba.txt ^ clear.txt

# B and C share their chunks:
xit b/chunk-bc.txt c/chunk-cb.txt ^ clear.txt

# A and C share their chunks:
xit a/chunk-ac.txt c/chunk-ca.txt ^ clear.txt

If you get all A, B, C's keys and xor them together, you can the clear back! It works because there are an odd number of holders. Guess what happens when the number is even?

xit a/* b/* c/* ^ clear.txt