File Exchange

image thumbnail

Substitution Cipher encoder and decoder

version (8.06 KB) by Dafydd Stephenson
A simple pair of functions to encode messages and decode them by means of frequency analysis.


Updated 22 May 2011

View License

This function uses frequency analysis to attack and decode messages
encoded using a /substitution cipher/ which exchanges each letter of the
alphabet for another. Unlike the famous "Caesar Shift" cipher, which
"shifts" the letters of the alphabet along by a certain amount, giving
just 26 possible ciphers, this has no specific order, giving 26!
possibilities. The function is very unlikely to work first time but,
depending of the length of the text, highly likely to get the letters "T"
and "E" correct. From here the user may spot an error in the decoding,
such as "TQE" which is obviously "THE", and the function offers them the
chance to swap the offending letters as often as is required. After a few
simple cases, the encrypted message is generally broken.
It removes all punctuation and case from the original
text. The other m-file can be used to encode messages in the substitution cipher, using a random arrangement of letters and giving the user the cipher key as well as encoded message.

Cite As

Dafydd Stephenson (2021). Substitution Cipher encoder and decoder (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

anwar diya

how use program, please?

ishan jaidka

Works really Great :)

ishan jaidka

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!