PYTHON IMPLEMENTATION OF VISUAL SECRET SHARING SCHEMES Ruxandra Olmd Faculty of Mathematcs and Computer Scence, Unversty of Bucharest Emal: ruxandra.olmd@fm.unbuc.ro Abstract Vsual secret sharng schemes (VSS) represent an mportant concept of vsual cryptography. They permt the sharng of a secret mage between multple partcpants so that only authorzed groups can recover the secret. Ths paper consders the software mplementaton of some black-and-whte secret mages VSS n Python programmng language. PIL (Python Imagng Lbrary) provdes strong mage processng capabltes, makng the lbrary sutable for ths knd of mplementaton. We present samples of the results obtaned from the software computaton and draw some conclusons. Keywords: vsual secret sharng, vsual cryptography, Python, PIL (Python Imagng Lbrary). Introducton A secret sharng scheme permts the sharng of a secret between multple partcpants so that only authorzed groups can recover the secret. Even by puttng ther s together, the members of an unauthorzed group are not able to reveal the secret or sgnfcant nformaton about t. Vsual secret sharng schemes (VSS) represent the partcular case for whch the secret and therefore the s are mages. Naor and Shamr were the frst to ntroduce them as a part of vsual cryptography [NAOR94]. Snce then, multple models of VSS were defned, for blackand-whte, grayscale or color pctures. Examples from the lterature ncludes [ATEN96] and [ITO99]. Ths paper exemplfes and analyses the mplementaton of some of the exstng VSS usng Python s Image Lbrary (PIL). Secton 2 defnes the VSS that were consdered for the mplementaton. Secton 3 ntroduces the resources and technques used durng development. Secton 4 exposes computatonal samples and data analyss. Fnally, we conclude. 2. Vsual Secret Sharng Schemes Ths secton ntroduces the VSS that were consdered for the software mplementaton. We restrct our nterest to black-and-whte secret mages, but a smlar approach can be consdered for color pctures as well. In most cases, the type of the s copes the type of the secret, n the sense that for a black-and-whte secret, the s are also black-and-whte mages. However, Ito and al. ntroduced a way to a black-and-whte secret mage nto colored mages components [ITO99]. A smlar, but smpler secret scheme that follows the same dea wll be consdered [OLIM]. Each mage (secret or ) s consdered to be a matrx of pxels. By conventon, n black-and-whte representaton, a whte pxel s represented by and a black pxel s
represented by. For color s, only R (red), G (green) and B (blue) pxels are used (no other combnaton of RGB colors can appear n a ). For the rest of the paper, P = { P,..., P n } denotes the set of partcpants and therefore n denotes ther number. Defnton. The collecton of all authorzed sets of partcpants to reconstruct the secret s called the access structure ( A ). The collecton of all forbdden sets of partcpants to access the secret s denoted by NA. Defnton 2. The collecton of the maxmal forbdden sets NA max s defned as NA max = { B NA B' NA \ B, B B'} Defnton 3. A secret sharng scheme s unanmous (or (n,n) secret sharng scheme) f all n s are needed n order to reconstruct the secret. In case of a unanmous secret sharng scheme, the access structure contans only set, the set of all partcpants. Ths represents a partcular type of access structure. If no restrctons are requred, then the access structure s called general access structure. The paper consders 3 types of black-and-whte secret mage VSS: ) unanmous vsual secret sharng scheme; 2) general access structure secret sharng scheme; 3) color s VSS. 2.. Naor-Shamr Unanmous VSS Naor and Shamr were the frst to ntroduce a vsual secret sharng scheme [NAOR94]. We wll restrct to ther unanmous scheme, the partcular case n whch all partcpants must agree to reconstructon. If at least one partcpant does not agree to ts component, the secret mage s perfectly secured (the others fnd no nformaton about the secret). ) Computng s Consder W = { e, e2,..., en} where n s the number of partcpants and e s the n- element vector wth on poston and otherwse. Let: π, π 2,..., π be the even cardnalty subsets of W ; 2 n σ σ 2,..., σ be the odd cardnalty subsets of W. n Each set defnes a, 2 2 n n matrx, S = ( ) and respectvely S = ( S ) : S n S = e π, =.. n, =..2 ; n S = e σ, =.. n, =..2 ; Consder: C, the set of matrces obtaned by permutng the columns of C, the set of matrces obtaned by permutng the columns of S ; S.
To each pxel n the secret mage wll correspond pxels n each : f the pxel s whte, an element from C s randomly chosen. The correspondng pxels n are gven by row of the selected matrx; f the pxel s black, an element from C s randomly chosen. The correspondng pxels n are gven by row of the selected matrx. 2) Reconstructon of the secret mage All s are added pxel by pxel (or the correspondng bts are OR -ed ). Theorem. The above scheme s a unanmous scheme wth n partcpants, where k = 2 n n s the number of pxels n each that correspond to a pxel n the secret; α = / 2 s the contrast parameter; r = 2 n! s the cardnal of C and C [NAOR94]. In order to obtan the exact orgnal secret mage, addtonal transformatons are needed. The 2 n pxel groups should be transformed n a black pxel, f the number of s s greater than the contrast parameter, or whte, otherwse. For the rest of the paper, we wll not consder ths mprovement. Example. Naor-Shamr unanmous VSS for n = 2 partcpants. From the constructon algorthm, the values of S and S are: S = ; S = The possble correspondng s of a pxel are summarzed n Table. 2 n Whte pxel Frst Second Result Black pxel Frst Second Result Table. All possble s n Naor-Shamr unanmous VSS wth 2 partcpants Example 2: Naor-Shamr unanmous VSS for n = 3 partcpants. From the constructon algorthm, the values of S and S are: S = ; S =
Some of the possble correspondng s of a pxel are dsplayed n Table 2. Whte pxel Frst Second Thrd Black pxel Table 2. Some possble s n Naor-Shamr unanmous VSS wth 3 partcpants Frst Result Frst Second Thrd Result Whte pxel Second Result Frst Black pxel Second Result Table 3. All possble s n Naor-Shamr unanmous VSS wth 2 partcpants that mantans mage rato constant Example 3: Naor-Shamr unanmous VSS for n = 2 partcpants that mantans the rato of the secret mage constant In prevous examples, n order to represent a pxel, one dmenson ncreases k tmes. To avod the dstorton of the mage, both dmensons can be ncreased by the same amount. Nevertheless, the dmenson of a becomes larger (Table 3).
2.2. General VSS The prevous schemes present the specal property of unanmty. Atenese and al. ntroduced a model of VSS that permts general access structures [ATEN96]. Defnton 4. Be P = { P,..., P n } the set of all partcpants and NA max = { B,..., B r } the collecton of the maxmal forbdden sets. The cumulatve array of the access structure A s defned as a n r matrx C (, where: A = b ) n, r b, P B =, P B The cumulatve array specfes f a partcpant P belongs to an unauthorzed maxmal set B, by settng the approprate element to. A scheme that allows a general access structure can be defned starng from the Naor- Shamr ( n, n) VSS: ) Computng s Let P = { P,..., P n } be the set of partcpants, A the access structure, NAmax the collecton of maxmal forbdden sets, t the cardnal of NAmax andc A the cumulatve array. S and S are defned as the matrxes from the unanmous Naor-Shamr scheme for t partcpants. For each fxed ( n) consder J = { C A (, ) = } and defne: S as the matrx wth row, of matrx S ; J S as the matrx wth row, of matrx S. J row equal to the result of applyng OR to all row equal to the result of applyng OR to all Consder: C, the set of matrces obtaned by permutng the columns of C, the set of matrces obtaned by permutng the columns of 2 n S ; To each pxel n the secret mage wll correspond pxels n each : f the pxel s whte, an element from C s randomly chosen. The correspondng pxels n are gven by row of the selected matrx; f the pxel s black, an element from C s randomly chosen. The correspondng pxels n are gven by row of the selected matrx. 2) Reconstructon of the secret mage All s are added pxel by pxel (or the correspondng bts are OR -ed ). S.
Example 4. A general VSS for n = 4 partcpant, and the collecton of the maxmal forbdden sets NA max = {{ P, P2 },{ P2, P3 },{ P3, P4 }}. From constructon: C A = As the cardnal of s 3, then the correspondng matrxes S and NAmax startng from S, respectvely S defned n Example 2: S = ; S = An example of sharng a whte, respectvely a black pxel s shown n Table 4. S are buld Whte pxel Frst Second Thrd Forth Black pxel Frst Second Thrd Forth Table 4. A possble sharng for a whte and a black pxel for the VSS n Example 4 2.3. Black-and-whte secret mage VSS wth RGB s Ito, Kuwakado and Tanaka used color components n order to a black-and-whte secret mage [ITO99]. We wll consder here a scheme that uses the same dea, but the pxels color (red, green or blue) n the components s (almost) randomly chosen from R, G and B [OLIM]. The usage of randomness elmnates the need of the fxed matrces, dea nherted from Naor-Shamr VSS. The scheme s avalable n the addtve RGB model, n whch whte results by addng red, green and blue together at maxmum ntensty, under the assumpton that addng any other color to whte t remans whte. Black s consdered to be the absence of any color. ) Computng s The pxels of the secret s are randomly choose from {R, G, B} so that: f the pxel of the secret mage s whte, then there must exst a component wth the correspondng pxel R, another component wth the correspondng pxel G and a thrd component, dfferent from the prevous two, wth the correspondng pxel B;
f the pxel of the secret mage s black, then all the correspondng pxels of the s are randomly choose from {R, G}, from {R, B} or from {G, B} so that there exst at least 2 pxels of dfferent colors. 2) Reconstructon of the secret mage k users try to reconstruct the secret by overlappng ther correspondent s (the s are added together, pxel by pxel); each colored computed pxel n the resultng mage s transformed nto a black pxel. Whte pxels reman unchanged. 4 examples of sharng are gven for a whte and respectvely a black pxel n Table 5. Please notce that for each whte pxel exst at least a red, a green and a blue, whle for a black pxel, the correspondng s have only 2 colors (R&G or R&B or B&G). 4 whte pxels Frst RR RR Second GR RB Thrd BB BG Forth RG GG Ffth RB GB Reconstructed color mage WW WW 4 black pxels Frst RR BB Second GB BB Thrd RR GB Forth RR GG Ffth RR GG Reconstructed color mage YM CC Table 5. A possble sharng for 4 whte and 4 black pxels n a scheme wth 5 partcpants (R = Red, G = Green, B=Blue, Y = Yellow, M = Magenta, C = Cyan, W=Whte) 3. Development envronment, mplementaton methods and technques The prevously mentoned VSS algorthms were mplemented n Python programmng language usng IDLE (Python s Integrated DeveLopment Envronment 2.6.6) as the development envronment [PYTH]. Python s a powerful dynamc programmng language, avalable for all maor operatng systems and avalable under an open source lcense. Besdes other benefts, Python was manly chosen due to the fact that t provdes a powerful and easy to use mage lbrary, named PIL (Python Image Lbrary), also avalable n a free verson. PIL provdes mage processng capabltes, avalable for dfferent knd of fle formats. A fully documentaton can be found at [PIL]. Some of the specal features that PIL provdes and were used durng the mplementaton nclude: Dfferent mage modes, defnng the type and depth of a pxel n the mage. Even though t supports multple standard modes, for the current mplementatons were used: o (-bt pxels, black and whte, stored as 8-bt pxels); o RGB (3x8-bt pxels, true color). The possblty to consder the mage as a matrx of pxels, permttng the modfcaton at pxel level, settng the pxel value, etc.;
Fgure. Graphcal nterfaces for 2 mplemented VSS Defnng or readng the sze of an mage as a 2-tuple consstng n the horzontal and vertcal sze n pxels (<mage>.sze); Workng wth bands of colors (R, G and B bands for color mages); Usng mage functons as: openng an exstng mage (mage.open(<mage>, <mode>)), creatng a new mage (mage.new(<mode>,<sze>)), creatng an mage based on multple bands of color (mage.merge(<mode>, (<band>, <band2>, <band3>))). Python also provdes other functons that were mandatory for the mplementaton of the VSS as: ntertools module, that standardzes effcent and useful tools for combnatorc generators as permutatons (ntertools.permutatons(<p>)) or combnatons (tertools.combnatons(<n>,<k>)); random module, that mplements pseudo-random generators: random.randrange([<start>], <stop>, <step>) returns a randomly selected element n the specfed range. All the prevously mentoned schemes were mplemented wthn graphcal nterfaces (Fgure ) that permt: to receve the secret mage as the nput fle; to fll n all the necessary parameters, dependng on the selected VSS (for example the number of partcpants for Naor-Shamr unanmous VSS or the number of partcpants and the collecton of maxmal forbdden sets for general access structure VSS); to compute the s accordngly to the flled n nputs; to reconstruct the mage based on the selected s (the selecton of dfferent set of s leads to dfferent reconstructed mages, dependng on the authorzaton of the group). Fgure 2. Input test mage
4. Software computaton and data analyss The mage n Fgure 2 was gven as the secret mage nput for all the mplemented VSS models. The other nputs are specfed below: Naor-Shamr unanmous VSS was tested for n = 3 partcpants (Fgure 3); Naor-Shamr unanmous VSS that mantans mage rato constant was tested for n = 2 partcpants (Fgure 4); The cumulatve VSS was tested as n Example 4, wth n = 4 partcpants and NA max = {{ P, P2 },{ P2, P3 },{ P3, P4 }} (Fgure 5); Black-and-whte secret mage VSS wth RGB s was tested for n = 4 partcpants (Fgure 6). Share Fgure 3.a. The s n the Naor-Shamr unanmous VSS (n = 3) Combned s Computed result Share Share Share Fgure 3.b. Computed mages by usng all possble sets of s n the Naor-Shamr unanmous VSS (n = 3) It s easy to remark that the practcal mplementaton supports the theory results. In case of Naor-Shamr unanmous VSS: The secret mage s reconstructed only by combnng together all the s. No nformaton s leaked when fewer partcpants cooperate; The reconstructed mage ncreases the length of the orgnal mage; The contrast of the reconstructed mage s decreasng (whte becomes gray);
Share Share 2 Fgure 4.a. The s n Naor-Shamr unanmous VSS (n = 2) that mantans the mage rato Combned s Computed result Share Fgure 4.b. The reconstructed mage from the s n the Naor-Shamr unanmous VSS (n = 2) that mantans the mage rato constant Share Share 4 Fgure 5.a. The s n the cumulatve VSS (n = 4) Combned s Computed result Share Share Share Share 4 Fgure 5.b. Sample of computed mages by usng dfferent sets of s n the cumulatve VSS (n = 4)
Share Share 3 Share 2 Share 4 Fgure 6.a. Shares n black-and-whte secret mage VSS wth RGB s (n = 4) Combned s Share Share Share Share 4 Computed result (color mage) Computed result (blackand-whte mage) Fgure 6.b. Sample of computed mages by usng dfferent sets of s n black-andwhte secret mage VSS wth RGB s (n = 4) In case of Naor-Shamr unanmous VSS that mantans the mage rato constant: The mage rato s mantaned constant; All the other propertes of the Naor-Shamr unanmous VSS are preserved: contrast s smaller than n the orgnal mage and the scheme s perfect n the sense that t provdes no nformaton about the secret when the number of cooperatng partcpants s less than n. In the case of the cumulatve general access structure VSS: The contrast of the reconstructed mage s decreasng; { P, P2 } s a maxmal forbdden group, so they are not able to reconstruct the secret mage;
By onng any other partcpant to a maxmal forbdden group, they become able to reconstruct the secret: for example { P, P2, P3 } can recover the secret mage (Fgure 5.b); Because P, P, P, } extends the maxmal forbdden set P, } (or { 2 3 P4 { P, P 3 4 { P2 P, }, or } ), t also represents an authorzed group of partcpants. But { P 2 3 even though the number of s s larger than n case of the set { P, P2, P3 }, the reconstructed mage s less smlar than the orgnal. In the case of the black-and-whte secret mage VSS wth RGB s: The dmenson of the s s equal to the dmenson of the secret, but more nformaton s needed for storage because of the color nformaton; The reconstructed mage mantans the rato of the ntal secret mage; Any 2 s provde no nformaton about the secret mage (the reconstructed mage s totally black); More than 2 s provdes enough nformaton (all black pxels are correctly reconstructed); All s lead to the perfect reconstructon of the ntal secret mage. 5. Conclusons The paper presents a possble mplementaton of some vsual secret schemes (VSS) under the Python programmng language, usng the PIL lbrary. Data nputs, computatonal results and a succnct analyss are performed for each consdered scheme. References: [ATEN96] Guseppe Atenese, Carlo Blundo, Alfred De Sants, Douglas R. Stnson, Vsual Cryptography for General Access Structures, Electronc Colloquum on Computatonal Complexty (ECCC), vol.3, no.2, 996. [GHOD98] Hossen Ghodos, Josef Peprzyk, Re Safar-Navn, Huaxong Wang, On constructon of Cumulatve Secret Sharng Schemes, LNCS, 998, pg.379-39. [ITO99] Ryo Ito, Hdenor Kuwakado, Hatsukazu Tanaka, Image Sze Invarant Vsual Cryptography, IEICE Trans. On Funda. Of Elect., Comm. And Comp.Sc., Vol.E82- A, No.(999), pg.272-277. [NAOR94] Mon Naor, Ad Shamr, Vsual Cryptography, Advanced n Cryptology EUROCRYPT 94, LNCS95, Sprnger-Verlag(995), pg.-2. [OLIM] Ruxandra Olmd, About a Vsual Secret Sharng Scheme, Proceedngs of the 3 rd Internatonal Conference on Securty for Informaton Tehnology and Communcatons, Bucharest, 2, pg. 3-7. [PIL] Python Image Lbrary (PIL) http://www.pythonware.com/products/pl/ [PYTH] Python Programmng Language Offcal Webste http://www.python.org/