- Notifications
You must be signed in to change notification settings - Fork3
CrypTools/RailfenceCipher
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A transposition cipher also called the zigzag cipher.
The Rail Fence Cipher places the letters in a zigzag pattern before reading them again, from top to bottom, right to left, ignoring the zigzag.
Example:
Let's imagine that we are encodingHello World!
on 3 rails. we draw out our three rails and place the lettres in the zigzag pattern like this:
H - - - o - - - r - - -- e - l - - o - l - !- - l - - - w - - - d -
When this is read top to bottom, left to right, we getHorel ol!lwd
Decoding is a bit harder. We can re-railfence the encoded string to find out how many characters there are per rail. From that, we can divide up the first encoded string into chunks according to their rail, and place them on a series of rails, to then read them according to the zigzag pattern.
Example:
First, we need to figure out how many characters there are per rail. We do this by re-encoding the already railfenced string and counting the characters per rail.
H - - - l - - - ! - - - 3 characters- o - e - - l - l - d 6 characterst- - r - - - o - - - w - 3 characters
Now we can divide the first string according to that 3, 6, 6 pattern, to getHor
,el lod!
,lwd
.Placing these onto a set of rails like these:
| - - - | - - - | - - -- | - | - | - | - | -|- - | - - - | - - - | -
We can are back to the original set of rails used to encode the message, and we are able to read the original message if we follow the zigzag pattern.
- The amount of rails is limited to half the length of the message. Brute force methods can therefore crack messages of reasonable length.
- Can easily be cracked by hand for shorter messages.
Language | Encrypt | Decrypt |
---|---|---|
Javascript | encrypt.js | decrypt.js |
Python | encrypt.py | decrypt.py |
Swift | lib.swift | lib.swift |
Tests are automatically handled byTravis CI.
Please readCONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We useSemVer for versioning. For the versions available, see thetags on this repository.
Made with ❤️ at CrypTools.
See also the list ofcontributors who participated in this project.
This project is licensed under the MIT License - see theLICENSE file for details