X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/canny.git/blobdiff_plain/8ee5d8b693307486fd2c72e82b9eb31af2f56ed0..e477428ed31d945b364bd9064476c1f0a34f86ef:/stc/exp/raphus/sobel555_for_ensemble.py diff --git a/stc/exp/raphus/sobel555_for_ensemble.py b/stc/exp/raphus/sobel555_for_ensemble.py index 89f8d98..4a31c20 100644 --- a/stc/exp/raphus/sobel555_for_ensemble.py +++ b/stc/exp/raphus/sobel555_for_ensemble.py @@ -8,8 +8,14 @@ import cv import os from random import * from math import * +from bbs import * + infinity = 1000000000 +M=18532395500947174450709383384936679868383424444311405679463280782405796233163977*39688644836832882526173831577536117815818454437810437210221644553381995813014959 +X=18532395500947174450709383384936679868383424444311 + + @@ -372,7 +378,12 @@ def compute_list_bit_to_change(threshold,processed): return List -def compute_filter_canny(level,image): +def compute_filter_canny(level,image,MsgLen): + + bbs = BlumBlumShub(); + bbs.setN(M) + bbs.setSeed(X) + level2=level.copy() level2= array(level2.getdata()).flatten() l=0 @@ -418,32 +429,44 @@ def compute_filter_canny(level,image): processed= array(processed.getdata()).flatten() List7=set(compute_list_bit_to_change(100,processed)) - nb_bit_embedded=(512*512/10)+40 + + nb_bit_embedded=max(2*MsgLen,int(len(List3)/MsgLen)*MsgLen) + print "nb_bit_embedded",nb_bit_embedded AvailablePixel3=List3 AvailablePixel5=AvailablePixel3.union(List5) AvailablePixel7=AvailablePixel5.union(List7) + sub=set() + if len(AvailablePixel3)>nb_bit_embedded: step=1 WorkingPixel=AvailablePixel3 + sub = bbs.sample(AvailablePixel3,nb_bit_embedded) elif len(AvailablePixel5)>nb_bit_embedded: step=2 WorkingPixel=AvailablePixel5 + sub = AvailablePixel3.union( + bbs.sample(AvailablePixel5-AvailablePixel3,nb_bit_embedded-len(AvailablePixel3))) + elif len(AvailablePixel7)>nb_bit_embedded: step=3 WorkingPixel=AvailablePixel7 + sub = AvailablePixel5.union( + bbs.sample(AvailablePixel7-AvailablePixel5,nb_bit_embedded-len(AvailablePixel5))) else: step=4 WorkingPixel=range(len(level2)) + sub = range(len(level2)) + print "avail P3",len(AvailablePixel3) print "avail P5",len(AvailablePixel5) print "avail P7",len(AvailablePixel7) - print "size WorkingPixel",len(WorkingPixel) - Weight=[0 for _ in WorkingPixel] + + Weight=[0 for _ in sub] l=0 - for i in WorkingPixel: + for i in sub: if step>=1 and i in List3: Weight[l]=1 if step>=2 and i in List5 and Weight[l]==0: @@ -454,76 +477,162 @@ def compute_filter_canny(level,image): Weight[l]=1000 l+=1 - - - - List_bit_to_change=WorkingPixel + List_bit_to_change=sub + return [sub,Weight] - return [List_bit_to_change,Weight] +def verifie(fileout,leng_msg,Message,): + global M,X + bit_to_read = 1 + dd2 = im.open(fileout) + dd2 = dd2.convert('RGB') + red2, green, blue = dd2.split() + level2=red2.copy() + [List_bit_to_change2,Weight2]=compute_filter_canny(level2,dd2,leng_msg) + level2= array(level2.getdata()).flatten() + print "support2",len(List_bit_to_change2) + print "message2",len(Message) + print "weight2",len(Weight2) + alpha = float(len(List_bit_to_change2))/len(Message) + assert alpha >= 2 + index = min(int(alpha),9) + H_hat2 = { + 2 : [71,109], + 3 : [95, 101, 121], + 4 : [81, 95, 107, 121], + 5 : [75, 95, 97, 105, 117], + 6 : [73, 83, 95, 103, 109, 123], + 7 : [69, 77, 93, 107, 111, 115, 121], + 8 : [69, 79, 81, 89, 93, 99, 107, 119], + 9 : [69, 79, 81, 89, 93, 99, 107, 119, 125] + }[index] -def mystego(filein, fileout): - dd = im.open(filein) - dd = dd.convert('RGB') - red, green, blue = dd.split() - level=red.copy() - [List_bit_to_change,Weight]=compute_filter_canny(level,dd) - level= array(level.getdata()).flatten() + print H_hat2 + + + Stc_message2=[getBit(level2[l],bit_to_read) for l in List_bit_to_change2] + LL2=list(List_bit_to_change2) + + """ + print "Level",max([level2[l]-level[l] for l in xrange(len(Stc_message2))]) + print "List bit to change",max([LL2[l]-LL1[l] for l in xrange(len(Stc_message))]) + print "Stc message", max([Stc_message[l]-Stc_message2[l] for l in xrange(len(Stc_message))]) + """ + Message2 = [x%2 for x in prod(H_hat2,len(Message),Stc_message2)] + level2=Message2 +# print "mesg",Message +# print "mesg2",Message2 - bit_to_read=1 + l=0 + val_mod2=0 + list_msg=[] + decoded_msg="" + bbs = BlumBlumShub(); + bbs.setN(M) + bbs.setSeed(X) - M=18532395500947174450709383384936679868383424444311405679463280782405796233163977*39688644836832882526173831577536117815818454437810437210221644553381995813014959 - # M clef - X=18532395500947174450709383384936679868383424444311 - # X clef + List_random=[] + while len(List_random)=leng_error*8 and val_mod2= 2 - index = min(int(alpha),9) - H_hat2 = { - 2 : [71,109], - 3 : [95, 101, 121], - 4 : [81, 95, 107, 121], - 5 : [75, 95, 97, 105, 117], - 6 : [73, 83, 95, 103, 109, 123], - 7 : [69, 77, 93, 107, 111, 115, 121], - 8 : [69, 79, 81, 89, 93, 99, 107, 119], - 9 : [69, 79, 81, 89, 93, 99, 107, 119, 125] - }[index] - - - print H_hat,H_hat2 - - - Stc_message2=[getBit(level2[l],bit_to_read) for l in List_bit_to_change] - LL1=list(List_bit_to_change); - LL2=list(List_bit_to_change2) - - print "Level",max([level2[l]-level[l] for l in xrange(len(Stc_message))]) - print "List bit to change",max([LL2[l]-LL1[l] for l in xrange(len(Stc_message))]) - print "Stc message", max([Stc_message[l]-Stc_message2[l] for l in xrange(len(Stc_message))]) - - Message2 = [x%2 for x in prod(H_hat2,len(Message),Stc_message2)] - level2=Message2 - -# print "mesg",Message -# print "mesg2",Message2 - - print equiv(Message,Message2) - - print "fini" - - l=0 - val_mod2=0 - list_msg=[] - decoded_msg="" - - MessageDecoded2=[(int(Message2[l])^int(List_random[l])) for l in xrange(len(Message2))] -# print conv_list_bit(''.join([`MessageDecoded2[i]` for i in xrange(leng_error*8)])) -# print int(conv_list_bit(''.join([`MessageDecoded2[i]` for i in xrange(leng_error*8)]))) - - print conv_list_bit(''.join([`MessageDecoded2[i]` for i in xrange(len(Message2))])) - - - - - - -# for l in List_bit_to_change2: -# if(val_mod2=leng_error*8 and val_mod2