Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Rail fence cipher

License

NotificationsYou must be signed in to change notification settings

CrypTools/RailfenceCipher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A transposition cipher also called the zigzag cipher.

How it works

Encoding

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

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.

Cons

  • 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.

Implementations

LanguageEncryptDecrypt
Javascriptencrypt.jsdecrypt.js
Pythonencrypt.pydecrypt.py
Swiftlib.swiftlib.swift

Running the tests

Tests are automatically handled byTravis CI.

Contributing

Please readCONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We useSemVer for versioning. For the versions available, see thetags on this repository.

Authors

Made with ❤️ at CrypTools.

See also the list ofcontributors who participated in this project.

License

This project is licensed under the MIT License - see theLICENSE file for details


[8]ページ先頭

©2009-2025 Movatter.jp