MATLAB code for Image Encryption/Decryption using ECC


Total downloads: 221

This is the code that simulates the encryption and decryption of an image using random and private keys in MATLAB. The elliptic curve cryptography is applied to achieve the security of any image before transmitting it to someone so that no one can see the data hidden in the image. At the receiver end, the destined user will already have the decryption key used for this. If the key is altered, the image will not be decrypted.

Note: The current  version of this code has a limited 5 trials and few protected files. Once the 5 trials are completed, the code will be deleted and MATLAB will be closed. To get the complete unprotected and unlimited trials, kindly write us at or whatsapp/call +91-9896101349

Download Code  Discuss Code



  • This is the code that simulates the encryption and decryption of an image using random and private keys in MATLAB.
  • After the pixel values are mapped onto the elliptical curve through the map table and then a public key is generated by the sender which is multiplied with each pixel value or point value.
  • The online image encryption and decryption code are generated in the MATLAB tool.
  • Another technique Logistic map and Arnold cat scrambling are used for the online image encryption and code is available at free-thesis.

This is the code that simulates the encryption and decryption of an image using random and private keys in MATLAB. This is the best online image encryption algorithm. In this, the elliptic curve cryptography is applied to achieve the security of any image before transmitting it to someone so that no other can see the data hidden in the image. At the receiver end, the destined user will already have the decryption key used for this. If the key is altered, the image will not be decrypted.

In the modern scenario, the digital images contain important information which required proper security while transmitting from one point to another. Security is valuable for some applications like military picture databases, medical imaging systems, and cable TV broadcasting. Image encryption has many benefits and it is the most popular security scheme of data or information processing.

Thesis statement ( Image encryption/decryption thesis)

In industries, confidential images are required security functions so that unauthorized access of images is not possible. For the encryption or decryption of images, some public and private keys are used. The private key image encryption/decryption process follows the symmetric cryptographic scheme, whereas asymmetric cryptographic systems use in the public key encryption image. In public-key cryptography, the encryption and decryption keys are not the same.

The pixel value of the image is first converted into the points and formed groups onto the elliptic curve finite field. All the programs are developed in the MATLAB software, and performance is measured via some security analysis parameters. Simulate the MATLAB script and observe the results with different stages of encrypting and decrypting process.

Elliptical Curve Cryptography (ECC)

Elliptical curve cryptography is a traditional approach to image encryption and decryption. The ECC (Elliptical Curve Cryptography) is a public key type and uses for those applications in which secure transmission channels are not available. In the image encryption process of ECC (Elliptical Curve Cryptography), the image message is mapped to the point on the curve and converting the mapped point into the message types. The quality of the image depends on the pixel value, and the image encryption process mapped these pixel values to point onto the curve.

ECC curve for various points

Figure 1 graph of an elliptical curve [1]

The ECC (Elliptical Curve Cryptography) is a private-public key pair used to encrypt and decrypt the data. ECC is asymmetric in nature which means for encryption a public key is used and decryption is retained via private key. The image pixel value is encrypted with the public key and decrypts the ciphertext later using the corresponding private key. The image pixel value is converted into the points on the Elliptical curve, then the mapping process is applied in the finite field.

A map table is created with respect to the group of elliptic points. A private key is applied to the mapped points and encrypted the pixel values of the image. Later a corresponding public key is used for the decryption process and retained the actual image from the encrypted image. The image encryption and decryption code are written in MATLAB.

Mapping Process

The image consists of pixel values for different formats, like a grayscale image containing 8-bit pixel values from 0 to 255. A color image consists of three octet values separately; shows Red, Green, and Blue intensity of color. An image is encrypted with ECC (Elliptical Curve Cryptography) considers each pixel as a message mapped to a point on the predefined elliptical curve. A map table is created with the help of the elliptic group generated first and then points are placed into the 256 groups. ECC(Elliptical Curve Cryptography) is used for the encryption of points after the mapping process of all pixel values of images related to point one by one. Mapping matrix generated after the code is debugging in MATLAB.

MATLAB Code Execution in Steps (Generic)

MATLAB, a matrix laboratory, is the software used by engineers and computer scientists for designing algorithms, data analysis, exploration, visualization, application development, and many more things. They also do image encryption and decryption using Matlab. The above-mentioned Matlab code for image encryption and decryption will stimulate the same for you.

AES image encryption code algorithm is also implemented with the help of the MATLAB platform. AES image encryption Matlab code makes a cipher Image from the original and vice versa.

Encryption and Decryption using MATLAB TOOL

  • The image pixel values generated the groups on the elliptical curve with different instant points after the mapping process. A point’s vector is added to all instant points generated in the group.
  • After the pixel values are mapped onto the elliptical curve through the map table and then a public key is generated by the sender which is multiplied with each pixel value or point value.
  • The pixel values of the image are encrypted using the public key onto the elliptic curve points.
  • The mapped or converted image is retained using possession of a secret public key. Each pixel value is retained, and the real image is reconstructed from the encrypted image.

This thesis provided the secure encryption and decryption of an image using ECC. The online image encryption and decryption code are generated in the MATLAB tool.

Another technique Logistic map and Arnold cat scrambling are used for the online image encryption and code are available at free-thesis.

Disclaimer: The following code is for demonstration purposes only. Without required functions, it will not execute. To run the code, the complete repository has to be downloaded.

Code Overview

Code Overview free-thesis

Step1: Generate Elliptic points

Each pixel in the image is considered as a message and it is mapped on a predefined elliptic curve. All possible points on the elliptic curve have to be generated first. The first step is to generate possible elliptic points on ECC curve.

p=123457;   % Prime number is selected
a=5376;     % constants a and b that satisfy the eq 4*a^3+27*b^2~=0.
for x=0:p
    for y=0:p
        if mod(y^2,p)==mod((x^3+a*x+b),p)  % This equation must be satisfied by x and y for the given value of a, b and p.
            eccpoints(i,:)=[x y];

eccpoints_all=[eccpoints; 0 0; 0 0;0 0;0 0;0 0];
for j=1:2:964
    for i=N:1:N+255
     x=eccpoints_all(i,:);  % The above points are arranged to map the intensity of pixels of the image.
     maptab(ii,j:j+1)=x;    %
maptab=[x maptab];

Step 2: Encrypt any image

This encryption code is scalable code and can be used on any size of image. Though we are demonstrating it on Lena image. As the image size increases, the computation time increases. The gray image conversion is done as preprocessing step. Generated Elliptic points in the previous step are used here. You need to enter the public and private keys and the same has to be used for the decryption.

%this code is used to encrypt and decrypt the image useng ECC
img=rgb2gray(imread('lena.jpg'));  % load any image
[Enc_Msg]=Encryption_1(img);    % This is process for encryption and output argument is having the set
                              % off point for each pixel which are mapped at
                              % the ECC curve.

Step 2.1. Encryption MATLAB Code Overview

The given code is an implementation of an image encryption algorithm using an elliptic curve cryptosystem (ECC). The encryption process is done by mapping the intensity values of each pixel of the image to points on an elliptic curve and then performing point addition between the mapped points and an encryption key point.

The algorithm takes an image as input and then initializes some constants and variables. The constants include the values of ‘a’ and ‘b’, which are chosen based on ECC equations, a prime number ‘p’, and a mapping table that is generated based on the values of ‘a’ and ‘b’. The variables include a random key ‘K’, a private key ‘Nb’, a base point ‘G’, which is used to generate public and encryption keys, and some variables for tracking the size and intensity values of the image.

The encryption process starts with looping through each pixel of the image and mapping its intensity value to a point on the elliptic curve using the mapping table. Then the mapped point is added to the encryption key point to generate a new point. The new point is then mapped back to an intensity value using the mapping table, and the encrypted intensity value is stored in a new image.

Finally, the encrypted image is displayed, and the encrypted points are returned as the output. The encryption key is not transmitted with the image but is generated by the sender and shared only with the receiver. The receiver then uses their private key to decrypt the image.

Step 3: Decrypt the image

Input the encrypted image and public-private (same as in the encryption step) keys to decrypt.

Decryption_1(Enc_Msg)   % This is the decryption process which recieve the ECC points as input
                        % and decryption key is generated and subtracted
                        % from all these points one by one. Again mapping
                        % is used to get the original image pixel.

Advantages of ECC

  • The ECC method is completely sensitive to the secret key so that the encrypted image cannot be decrypted while making some changes in the secret key.
  • The entropy value is higher (8) which provides the optimal length of the code assigned to the pixel of an image.
  • The range of the correlation coefficient must be lie between 0 to 1. The adjacent pixels correlation coefficient is maximum for better security.
  • The input image contains some information that can be extracted for the encryption process. So histogram analysis provided the spectrum analysis of information of input and encrypted image.
  • The secret key size is smaller.
  • Low mathematical complexity.
  • High-speed encryption.
  • Brute force attack is impracticable for elliptical curve cryptography due to its logarithmic type of nature.


In this work, the ECC (Elliptical Curve Cryptography) algorithm is proposed for the online image encryption and decryption process. ECC (Elliptical Curve Cryptography) is provided fast encryption and use for high information images. The mapping is performed for the conversion of pixel value into the point of an affine elliptic curve over a finite field using the map table. The encryption process is very fast and low complex in nature. The strength of the algorithm is checked by the security analysis function like histogram, key security, and correlation.

Published Paper similar to this work

This image encryption code can be used in the following and other similar research papers.

  1. Latha, H. R., and A. Ramaprasath. “Optimized Two-Dimensional Chaotic Mapping for Enhanced Image Security Using Sea Lion Algorithm.” In Emerging Research in Computing, Information, Communication and Applications, pp. 981-998. Springer, Singapore, 2022.
  2. Dastidar, Ananya, and Sonali Mishra. “Encryption and Decryption Algorithms for IoT Device Communication.” Electronic Devices and Circuit Design: Challenges and Applications in the Internet of Things (2022): 97-112.
  3. Hafsa, Amal, Anissa Sghaier, Jihene Malek, and Mohsen Machhout. “Image encryption method based on improved ECC and modified AES algorithm.” Multimedia Tools and Applications 80, no. 13 (2021): 19769-19801.
  4. Chillali, Sara, and Lahcen Oughdir. “ECC Image Encryption Using Matlab Simulink Blockset.” In International Conference on Digital Technologies and Applications, pp. 835-846. Springer, Cham, 2021.


  1. Soleymani, Ali, Md Jan Nordin, Azadeh Noori Hoshyar, Zulkarnain Md Ali, and Elankovan Sundararajan. “An image encryption scheme based on elliptic curve and a novel mapping method.” International Journal of Digital Content Technology and its Applications7, no. 13 (2013): 85.
  2. Astya, Dr ParmaNand, Ms Bhairvee Singh, and Mr Divyanshu Chauhan. “Image encryption and decryption using elliptic curve cryptography.” International Journal of Advance Research In Science And Engineering IJARSE3 (2014).
  3. Singh, Laiphrakpam Dolendro, and Khumanthem Manglem Singh. “Image encryption using elliptic curve cryptography.” Procedia Computer Science54 (2015): 472-481.
  4. Soleymani, Ali, Md Jan Nordin, and Zulkarnain Md Ali. “A Novel Public Key Image Encryption Based on Elliptic Curves over Prime Group Field.” Journal of Image and Graphics1, no. 1 (2013): 43-49.
  5. Nagaraj, Srinivasan, G. S. V. P. Raju, and K. Koteswara Rao. “Image encryption using elliptic curve cryptograhy and matrix.” Procedia Computer Science48 (2015): 276-281.
  6. Shankar, Tarun Narayan, and G. Sahoo. “Cryptography by karatsuba multiplier with ASCII codes.” International journal on computer applications(2010): 53-60.

admin is an innovative and first of its kind platform created by Vidhilekha Soft Solutions Pvt Ltd, a Startup recognized by the Department For Promotion Of Industry And Internal Trade, Ministry of Commerce and Industry, Government of India recognised innovative research startup.

90 reviews for MATLAB code for Image Encryption/Decryption using ECC

  1. gajanan.bhusare (verified owner)


  2. gajanan.bhusare (verified owner)


  3. gajanan.bhusare (verified owner)


  4. aaryan.aggarwal (verified owner)


  5. aaryan.aggarwal (verified owner)


  6. krisma.ziliwu (verified owner)


  7. krisma.ziliwu (verified owner)


  8. subham.pramanik (verified owner)


  9. nandan.kumar (verified owner)


  10. alal.lolo (verified owner)


  11. jjj.jjj (verified owner)


  12. aaryan.nehra (verified owner)


  13. alaa.elbanna (verified owner)

    it is okey

  14. alaa.elbanna (verified owner)

    it is very good to have such as code in my research

  15. kavipriya.suresh (verified owner)


  16. kavipriya.suresh (verified owner)


  17. duongdz210 (verified owner)


  18. melvin.lesilolo (verified owner)


  19. melvin.lesilolo (verified owner)


  20. sandeep.sandy (verified owner)


  21. muhammad alqi.fahrezi (verified owner)


  22. hhhh.kiou (verified owner)


  23. pechetti.sujani (verified owner)


  24. darshan.ghumed (verified owner)


  25. dbsignup (verified owner)


  26. dbsignup (verified owner)


  27. (verified owner)

    thank you very much

  28. rishu.pandey (verified owner)


  29. darshan.ghumed (verified owner)


  30. sujarani.r (verified owner)

    why u ask rating before download

  31. tom.fairbanks (verified owner)


  32. dil.s (verified owner)


  33. dil.s (verified owner)


  34. dil.s (verified owner)


  35. todg.uter (verified owner)


  36. arun.s-8124 (verified owner)


  37. nithin.m (verified owner)


  38. nithin.m (verified owner)


  39. shourya.gupta (verified owner)


  40. alaoui.alaoui (verified owner)

    gooof code

  41. rajeevan.v (verified owner)


  42. mohammadsaeed01 (verified owner)

    Thanks for this complete example

  43. iqbiuhqh.qhdchbihjqqqqqqqqqqq (verified owner)


  44. kaviya.n (verified owner)


  45. rohit.vp (verified owner)


  46. rohit.vp (verified owner)

    Not working

  47. abhishek.sudhir (verified owner)


  48. cao.nguyen duy (verified owner)


  49. adla.sanober (verified owner)

    thanks for code

  50. cao.nguyen duy (verified owner)

    nice project

  51. e1w.w (verified owner)


  52. andrea.ortega (verified owner)

    OK. TKs

  53. anil.kumar-6959 (verified owner)


  54. jay.khinchi (verified owner)


  55. g vignesh.vignesh (verified owner)


  56. Himanshu (verified owner)

    please send

  57. jay.khinchi (verified owner)


  58. jay.khinchi (verified owner)


  59. jay.khinchi (verified owner)


  60. jay.khinchi (verified owner)


  61. jay.khinchi (verified owner)


  62. jay.khinchi (verified owner)


  63. jay.khinchi (verified owner)


  64. jay.khinchi (verified owner)


  65. ali.broumandnia (verified owner)


  66. harshavardhan.s (verified owner)

    Better one

  67. jay.khinchi-7589 (verified owner)


  68. jay.khinchi-7589 (verified owner)


  69. nagomi.s (verified owner)


  70. nagomi.s (verified owner)


  71. gahj.aas (verified owner)

    no comment

  72. aditi (verified owner)

    thankyou for the help

  73. aarush.vish (verified owner)


  74. mftasdemir (verified owner)


  75. werter.folks (verified owner)

    Your platform is great! I will always be with you.

  76. werter.folks (verified owner)


  77. varsha.v (verified owner)

    very good

  78. varsha.v (verified owner)

    very good

  79. subham.roy (verified owner)


  80. anjibabu.komari (verified owner)

    this is will be very useful for my final project

  81. abdulraufgarba (verified owner)

    this is very helpul

  82. santhikumar (verified owner)

    thank you

  83. alaoui.alaoui (verified owner)


  84. alaoui.alaoui (verified owner)


  85. aruna.r (verified owner)

    Thank you

  86. pravin.kumar (verified owner)


  87. pravin.kumar (verified owner)


  88. pravin.kumar (verified owner)


  89. sam.heard (verified owner)

    fake or real to be seen

  90. chandru.s (verified owner)


Only logged in customers who have purchased this product may leave a review.