.st0{fill:#FFFFFF;}

Symmetric Key Cryptography using MATLAB 

 May 25, 2020

By  Manoj sai

Introduction

MATLAB is a multi-paradigm numerical computing environment and proprietary programming language developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages.

In our day-to-day life, we are sending and receiving much information from the internet. This information is transmitting through a transmission line, this channel is always insecure, and anything can be seen by anyone, not only just seeing they can actually modify the data.

In this insecure channel, all our information is not actually passed by what we send. Data will be encrypted before sending it into the channel, and the encrypted is transferred through the transmission line. Now even if anyone captures the data, then they will get the encrypted data and not the actual data.

You might get one question of how the actual receiver will get the actual data? Yes, without the key and algorithm used by the sender, it is impossible to retrieve the actual data.

Description

Flow chart symmetric key crypto system

Symmetric encryption was the only type of encryption in the 1970’s. Before beginning, we define some terms. An original message is called Plaintext, while the coded message is called Cipher text. The process of converting from plaintext to cipher text is known as Encryption or Enciphering; restoring the plaintext from the cipher text is Decryption or Deciphering.

During encryption, the sender uses the algorithm and key to encrypt the data,

C=E (K, P)

Where, C is cipher (the encrypted data);

              E is encryption algorithm;

              K is the secret key

              P is plaintext (the actual data).

Now, assume the receiver knows the key and the ciphertext. Decryption is the process of retrieving the actual data from the cipher. It is the exact reverse process of encryption,

P=D (K, C)

Where, P is plaintext (the actual data);

             D is the decryption algorithm;

             K is the secret key;

             C is cipher (the encrypted data).

Points to be remembered:


  • The same algorithm with the same key is used for encryption and decryption.
  • The sender and receiver must share the algorithm and the key.
  • The key must be kept secret.
  • It must be impossible or at least impractical to decipher a message if no other information is available.
  • Knowledge of the algorithm plus samples of ciphertext must be insufficient to determine the key.

Code

Get Access to
Code & Report!

Implement a real-time Symmetric Key Cryptography system where we send and receive data securely using MATLAB; Developed with MATLAB R2019b

Here, we considered an encryption process where we use the Fibonacci series. The encryption algorithm process is as follows:

Fibonacci Function


Step1: Creating a function that generates a Fibonacci series with same length of plaintext

             Here, l=length of plaintext

                       f=array of Fibonacci series

Sender


 Step2: Creating cipher, an array of elements by adding the given key, the generated Fibonacci series, and the plain text

                  Here, k=Key(an alphabet)

                             ptext=plain text         

Step3: Creating a text file containing the generated cipher text which will be shared to the receiver via transmission line.

Receiver


Step4:   Copying the content of text file that is shared into the cipher array

Step5: Decrypting the cipher by subtracting the key, the Fibonacci series of same length as cipher text from the cipher. The resultant array containing integer numbers(ASCII values) should be converted to characters

Result

The sender wants to send the plaintext as MATLAB Helper, and the key is k.

Screenshots of command window showing plain text

After running the sender side code, a confirmation message was printed on the screen

Now, the text file will contain the cipher text
SS of command window showing cypher text

The receiver should enter the correct key k

ss of command window showing correct text
Now receiver retrieved the plaintext back

If the receiver enters a wrong key, say x
ss of command window showing wrong text
Now, the receiver got a wrong plaintext.

So, the key should be kept secret. We can interpret this key with our house key, whoever has the access of key can enter into the house likewise here also without knowing the key we cannot know the plaintext

Conclusion

In Cryptography all encryption algorithms are based on two general principles: substitution, in which element in the plaintext is mapped into another element, and transposition, in which elements in the plaintext are rearranged. The fundamental principle is that no information be lost 

An encryption algorithm can strive for is an algorithm that meets one or both of the following criteria:

  • The cost of breaking the cipher exceeds the value of the encrypted information.
  • The time required to break the cipher exceeds the useful lifetime of the information.

An encryption scheme is said to be computationally secure if either of the foregoing two criteria are met.

Thus, we successfully transmitted the data securely in an insecure channel using symmetric-key cryptography in MATLAB.

Did you find some helpful content from our video or article and now looking for its code, model, or application? You can purchase the specific Title, if available, and instantly get the download link.

Thank you for reading this blog. Do share this blog if you found it helpful. If you have any queries, post them in the comments or contact us by emailing your questions to [email protected]. Follow us on LinkedIn Facebook, and Subscribe to our YouTube Channel. If you find any bug or error on this or any other page on our website, please inform us & we will correct it.

If you are looking for free help, you can post your comment below & wait for any community member to respond, which is not guaranteed. You can book Expert Help, a paid service, and get assistance in your requirement. If your timeline allows, we recommend you book the Research Assistance plan. If you want to get trained in MATLAB or Simulink, you may join one of our training modules. 

If you are ready for the paid service, share your requirement with necessary attachments & inform us about any Service preference along with the timeline. Once evaluated, we will revert to you with more details and the next suggested step.

Education is our future. MATLAB is our feature. Happy MATLABing!

About the author 

Manoj sai

I am currently pursuing b.tech, always interested to learn new things, and a good listener. I strongly believe that " Dream, Dream Dream, Dreams transform into thoughts and thoughts result in action." - Abdul Kalam

  • Abhishek Agrawal says:

    The implementation of the Fibonacci series for encryption process was a great idea and overall a well structured algorithm for symmetric key cryptography.

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    MATLAB Helper ®

    Follow: YouTube Channel, LinkedIn Company, Facebook Page, Instagram Page

    Join Community of MATLAB Enthusiasts: Facebook Group, Telegram, LinkedIn Group

    Use Website Chat or WhatsApp at +91-8104622179

    >