cryptoHome One-Time Pad Cipher

Background

Cryptographically "perfect" (information-theoretically secure), this cipher uses a truly random encryption that varies for each character of the message, making it immune to occurrence frequency analysis and brute-force attack.

We create a unique one-use "pad" (originally just a sequence of numbers scrawled on a paper pad, using pen) of individual random letter shifts that are only useful in encrypting/decrypting that particular message. It is discarded after use. Presumably both sender and receiver have some secure methor of exchanging the message and the pad.

The resulting ciphertext will be impossible to decrypt or break (according to wiki) if the following four conditions are met:

This version includes the "space" character in the defined "alphabet" to further mess with the would be message hacker - the net effect is that spaces appear randomly in the ciphertext, regardless of where they were in the cleartext, which is fun. You can arbitrarily decide on the character set included in the "alphabet" to make messages that include other characters I suppose.

Want your own PAD? - GENERATE your own

Example:

ABCDEFGHIJKLMNOPQRSTUVWXYZ

Cleartext: C O D E
Pad(random): 1 20 14 0
Ciphertext: D I R E

 

Code

Let's try it out:

Pad (leave blank if encrypting):
Message:


Algorithm


BEGIN
	SET answer=''
	SET alphabet = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	INPUT mode
	INPUT uppercase(message)
	SET msgLength = length of message

	IF mode = 'encrypt' THEN

		SET pad = []
		FOR each char in message
			APPEND random(0..length of alphabet) to pad
			SET pos = character position of current char in alphabet
			CALCULATE newpos = (pos + corresponding pad entry) mod (length of alphabet)
			SET answer += alphabet[newpos]
		ENDFOR
		OUTPUT answer
		OUTPUT pad

	ELSE
		INPUT pad
		PARSE pad into array
		FOR each char in message
			SET pos = character position of current char in alphabet
			CALCULATE newpos = (pos - corresponding pad entry) mod (length of alphabet)
			SET answer += alphabet[newpos]
		ENDFOR
		OUTPUT answer
	ENDIF
END