📜 ⬆️ ⬇️

Implementation of the secret visual information sharing scheme in MATLAB

Introduction

Good day to all!

I am sure that many of you were already interested in the methods of sharing secret visual information. If this is so, then you are certainly familiar with the work of Moni Naor and Adi Shamir on visual cryptography, as well as with the post of April 19, 2013. The scheme of sharing secret visual information . I studied the algorithm and function code written in MATLAB, proposed in this article, and came to the conclusion that it was not rationally written: it can be written much shorter, as well as improve its efficiency. How to do this, I will describe below. Also consider how to organize.

Code optimization

The disadvantage of this function is that the program repeatedly repeats the same type of code, which increases the size of the function, complicates its implementation, while the tools available in MATLAB allow you to write it shorter.

I propose to optimize the getShdwImg function code as follows:
')
function [S1,S2] =getShdwImgrac2x2(Img) %    S1  S2     (Img) % %     [m,n] = size(Img); %       :) S1= zeros(2*m,2*n); S2= zeros(2*m,2*n); r1=[1 0; 1 0]; r2=[0 1; 0 1]; r3=[0 0; 1 1]; r4=[1 1; 0 0]; r5=[1 0; 0 1]; r6=[0 1; 1 0]; r=cat(3, r1, r2, r3, r4, r5, r6); %      -   . 1 % : for i=1:m-1 for j=1:n-1 k = randi(6); if(Img(i,j)==1) S1(2*i-1:2*i, 2*j-1:2*j)=r(:,:,k); S2(2*i-1:2*i, 2*j-1:2*j)=r(:,:,k); else if (mod(k,2) == 0) S1(2*i-1:2*i, 2*j-1:2*j)=r(:,:,k); S2(2*i-1:2*i, 2*j-1:2*j)=r(:,:,k-1); else S1(2*i-1:2*i, 2*j-1:2*j)=r(:,:,k); S2(2*i-1:2*i, 2*j-1:2*j)=r(:,:,k+1); end end end end 


Let us consider in detail what the differences of this code are in comparison with the source code:



image
Source image

image
Original image converted to binary

image
First shadow image

image
Second shadow image

image
Image obtained by combining two shadow images using the logical operator ~ xor

And now I bring to your attention the function code for Shamir's secret sharing scheme (3.3) for the binary image.

Development of the function code for the Shamir secret secret separation scheme (3.3) for a binary image

This function is intended for dividing an image into three shadow ones. The original image can be restored only by matching all three shadow images. In general, its code is similar to the code outlined above, but it has a number of significant additions.

 function [S1,S2,S3] =getShdwImgrac3x3opt(Img) %        % S1, S2, S3     (Img) % %     [m,n] = size(Img); %  3        ) S1= zeros(2*m,2*n); S2= zeros(2*m,2*n); S3= zeros(2*m,2*n); %        c01=[0 0 1 1; 0 1 0 1; 0 1 1 0]; c02=[1 0 0 1; 1 0 1 0; 0 0 1 1]; c03=[1 1 0 0; 0 1 0 1; 1 0 0 1]; c04=[0 1 1 0; 1 0 1 0; 1 1 0 0]; c0=cat(3, c01, c02, c03, c04); c05=[1 1 0 0; 1 0 1 0; 1 0 0 1]; c06=[0 1 1 0; 0 1 0 1; 1 1 0 0]; c07=[0 0 1 1; 1 0 1 0; 0 1 1 0]; c08=[1 0 0 1; 0 1 0 1; 0 0 1 1]; c1=cat(3, c05, c06, c07, c08); %       3   %  for i=1:m-1 for j=1:n-1 d=randi(4); %     c k = randperm(3); %   if(Img(i,j)==1) S1(2*i-1:2*i, 2*j-1:2*j)=reshape(c0(k(1),1:4,d), 2, 2); S2(2*i-1:2*i, 2*j-1:2*j)=reshape(c0(k(2),1:4,d), 2, 2); S3(2*i-1:2*i, 2*j-1:2*j)=reshape(c0(k(3),1:4,d), 2, 2); else S1(2*i-1:2*i, 2*j-1:2*j)=reshape(c1(1,1:4, d), 2, 2); S2(2*i-1:2*i, 2*j-1:2*j)=reshape(c1(2,1:4, d), 2, 2); S3(2*i-1:2*i, 2*j-1:2*j)=reshape(c1(3,1:4, d), 2, 2); end end end 


Let us consider in more detail the differences between the getShdwImgrac3x3opt function and the getShdwImgrac2x2 function.



Thanks to everyone who read it. Good luck!

Source: https://habr.com/ru/post/226859/


All Articles