# Cryptography

## Some classic encryption algorithms.

### Caesar's Cyher

Julius Caesar is said to have used this encryptions scheme while sending out military instructions to his generals.

This is a very simple method - it basically moves a letter three places forward - 'a' becomes 'd', 'b' becomes 'e' and so on.

### Enigma Machine Encryption

Enigma Machine is a device used in World War II by Germany for encryption and decryption of top secret documents. It was a simple machine, but it created an encryption scheme that where extremely difficult to crack. In the end, a polish mathamatican cracked the code - it was one of the main reasons behind the allied victory of World War II.

Enigma Machine looked like ordinary typewriters. They had all the keys that where necessary on them and had an output with bulbs under every letter. When a key is pressed, the bulb under the letter corresponding to that key was lit. In between the key and the bulb the wires went through some wheels. The first models of Enigma machines had four wheels(like my program). Later, more advanced machines were created - some having upto 16 wheels.

Download a Java version of Enigma Machine using 2 wheels. Be careful of this - this is my first Java Program and has a lot of bugs. Try the JavaScript version above - that is much better.

### ROT-13

'Rotate alphabet 13 places'. The simple Caesar-cypher encryption that replaces each English letter with the one 13 places forward or back along the alphabet, so that "The butler did it!" becomes "Gur ohgyre qvq vg!" A major advantage of ROT-13 over rot(N) for other N is that it is self-inverse, so the same code can be used for encoding and decoding. So if you click the button two times, you get the original message back.

### Binny's Re-Encryption Method

This is perhaps the easiest encryption to do - just 1 line of code is enough. This methord uses the Regular Expressions.
`encrypted = txt.replace(/(.)(.)(.)(.)(.)(.)(.)/g,"\$3\$6\$7\$1\$2\$4\$5")`
Decryption is just as simple...
`decrypted = txt.replace(/(.)(.)(.)(.)(.)(.)(.)/g,"\$4\$5\$1\$6\$7\$2\$3")`

This basically mixes the letters around.
One can use any good text editor, which has regular expression search and replace support to encrypt a file. Just open a file and replace the regular expression "(.)(.)(.)(.)(.)(.)(.)" with the string "\3\6\7\1\2\4\5". To decrypt it, just replace "(.)(.)(.)(.)(.)(.)(.)" with "/4/5/1/6/7/2/3". Or you can use grep to do it for you. Another feature of this scheme is that one can modify the encryption as he/she likes very easily.