Visual Cryptography)

Source: Internet
Author: User

First look:

Change the transparency of one image to 50%. After overlapping the two images:

Source: http://leemon.com/crypto/VisualCrypto.html

 

You can check it out first. The author means that Party A and Party B need to transmit the message. They can say a key in advance and send the stream (plaintext) image to the party when passing the message, and the other party decrypts it, you only need to enter the key and the corresponding message length (enter equal space) to get the ciphertext (key) image, and finally get the message content. The same key image can match multiple plaintext images.

 

The principle is very simple. Based on the given password (passphrase), the author uses two images to form an image, which is only related to the password. Then, the opposite image is used for the encrypted content, and the original image needs to be replaced, so that the two images can be stacked to achieve the desired effect.

 

I will not discuss the quality of such encryption for the time being. I am amazed to see the last font array of the author.

 

If you want to write a program that supports Chinese characters, you can use the C # version of visualcrypto.

Because caozhy is used for Dot Matrix ExtractionProgram:

See http://topic.csdn.net/u/20120629/17/a33f88b5-7ee8-4a0c-8915-c0c721bb30c9.html

 

 

Source code has been uploaded: http://files.cnblogs.com/nanqi/VisualCryptography.zip

 

Personal thoughts:

First, replace it with the private field _ unit.

Bool [] [] _ unit = new bool [] [] {New bool [] {true, false, false, true}, new bool [] {false, true, true, false }};

 

Process the password entered by the user as a bool [256] datacode, that is, a 16*16 matrix.

If it is true, the first is used. If it is false, the second is used. Finally, the bool [1024] _ resultcode is obtained, that is, the 32*32 matrix.

 

Obtain the bool [256] datamsg (16*16 matrix) through the modulo lattice.

 

Compared with the bool [256] datacode obtained by the password, the bool [256] datadiff is generated. If the value of datamsg is false, the inverse of the datacode is not changed.

Same as the method for obtaining resultcode, use datadiff to obtain the corresponding _ resultmsg.

 

Draw two diagrams.

 

DetailsCode:

1   //  Password  2   Byte [] Code = System. Text. encoding. Default. getbytes (textbox1.text. Trim ());  3   4   If (Code. Length = 0  )  5   {  6 Code = Def_code;  7  }  8   Else   If (Code. length> 16  )  9   {  10 Code = code. Take ( 16  ). Toarray ();  11   }  12   Else  13   { 14      While (Code. Length < 4  )  15   {  16 Code = Code. Concat (CODE). toarray ();  17   }  18   }  19   20 Code = Code. Concat (def_code.skip (code. Length). toarray (); 21   22 Ienumerable < Byte > Tmpdatacode = enumerable. Empty < Byte > ();  23   24   For ( Int I = 0 ; I <code. length; I + = 4  )  25   {  26 Tmpdatacode = tmpdatacode. Concat (sha512encrypt (code. Where (by, index) => (index & 3 ) = (I/ 4 & 3  ). Toarray ()));  27   }  28   29   Bool [] Datacode = tmpdatacode. Select (by => convert. toboolean (& 1 ). Toarray ();

 

 //  Model Bitmap BMP =New Bitmap ( 16 , 16  ); Graphics g = Graphics. fromimage (BMP); G. fillrectangle (brushes. White,  New Rectangle () {x = 0 , Y = 0 , Height = 16 , Width = 16  }); G. drawstring (textbox2.text, textbox2.font, brushes. Black, point. Empty );  Bool [] Datamsg = enumerable. Range (0 , 256 ). Select (A => New {X = A % 16 , Y =/ 16  }). Select (x => BMP. getpixel (x. x, x. y). getbrightness ()> 0.5f ? False : True ). Toarray ();

 

 1   //  Difference  2  Bool [] Datadiff = Datacode. toarray ();  3   4   If (Datamsg. Length = Datacode. length)  5   {  6      For ( Int I = 0 ; I <datamsg. length; I ++ )  7   { 8 Datadiff [I] = datamsg [I]? Datadiff [I]:! Datadiff [I];  9   }  10   }  11   12   //  Key  13 Ienumerable < Bool > Tmpresultcode = enumerable. Empty < Bool > ();  14  15   Foreach ( VaR Item In  Datacode)  16   {  17 Tmpresultcode = Tmpresultcode. Concat (_ Unit [convert. toint32 (item)]);  18   }  19   20 _ Resultcode = Tmpresultcode. toarray ();  21  22   23   //  Message  24 Ienumerable < Bool > Tmpresultmsg = enumerable. Empty < Bool > ();  25   26   Foreach ( VaR Item In  Datadiff)  27  {  28 Tmpresultmsg = Tmpresultmsg. Concat (_ Unit [convert. toint32 (item)]);  29 }

 

 Void Draw (Graphics G, Bool  [] Data ){  For ( Int I = 0 ; I < 16 ; I ++ )  For (Int J = 0 ; J < 16 ; J ++ )  For ( Int K = 0 ; K < 4 ; K ++ ) {Brush = Data [J * 4 * 16 + I * 4 + K]? Brushes. Black: brushes. White; If (K < 2  ) G. fillrectangle (brush,  New Rectangle () {x = I * 16 + K * 8 , Y = J * 16 , Width = 8 , Height = 8  });  Else  G. fillrectangle (brush,  New Rectangle () {x = I *16 + (K- 2 )* 8 , Y = J * 16 + 8 , Width = 8 , Height = 8  });}} 

 

Source: http://leemon.com/crypto/VisualCrypto.html

See http://topic.csdn.net/u/20120629/17/a33f88b5-7ee8-4a0c-8915-c0c721bb30c9.html

Source code: http://files.cnblogs.com/nanqi/VisualCryptography.zip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.