|
begin process at 2008 07 05 20:30:45
Derniers logiciels
|
Trouver une ressource (Nouvelle version du moteur, plus rapide & pertinent, essayez le !)
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
STEGANOGRAPHIE
Information sur la source
Description
Simple programme en mode console pour cacher du texte dans une image .bmp . Avec le module PIL , pardonner le manque de commentaire
Source
- #!/usr/bin/python
- # -*- coding: iso8859-1 -*-
-
- from Image import open,new
- from sys import argv,exit
- from os import access,F_OK
- from string import split
-
-
- def ConstrcutRGB(pixelR,pixelG,pixelB,lenP):
- i = 0
- pixel = []
- while ( i < lenP ):
- pixel.append((pixelR[i],pixelG[i],pixelB[i])) # (( )) Car on fait une liste de tuple
- i += 1
- print ("[*] Rassemble RGB -> liste -> tuple : ok .")
- return pixel
-
- def ConverCharInt():
- txt = raw_input("Texte -> ")
- txt += "FiNiEnD"
- chiffreTexte,i = [],0
- decimal = []
- while ( i < len(txt) ):
- chiffreTexte.append(ord(txt[i])+100)
- i += 1
- i = 0
- i2 = 0
- while ( i < len(chiffreTexte) ) :
- i2 = 0
- buff = str(chiffreTexte[i])
- while ( i2 < len(buff) ):
- decimal.append(buff[i2])
- i2 += 1
- i += 1
- return decimal
-
- def ModifValeurPixel(pixel,valeur):
- if ( pixel > 245 ):
- pixel[i] = 244
- buff = str(pixel)
- buff = buff[:len(buff)-1]
- buff = buff+str(valeur)
- pixel = buff
- return pixel
-
- def CacheTexte(pixelR,pixelG,pixelB,decimal,lenPixel,size,newImg):
- i=0
- i_d=0
- while ( i < lenPixel ):
- pixelR[i] = ModifValeurPixel(pixelR[i],decimal[i_d])
- i_d += 1
- if ( i_d == len(decimal) ):
- break
- pixelG[i] = ModifValeurPixel(pixelG[i],decimal[i_d])
- i_d += 1
- if ( i_d == len(decimal) ):
- break
- pixelB[i] = ModifValeurPixel(pixelB[i],decimal[i_d])
- i_d += 1
- if ( i_d == len(decimal) ):
- break
- i += 1
- print("[*] Modifie valeur : ok ")
- i = 0
- while ( i < lenPixel ):
- pixelR[i] = int(pixelR[i])
- pixelG[i] = int(pixelG[i])
- pixelB[i] = int(pixelB[i])
- i += 1
-
- newImage = new('RGB',size)
- newImage.putdata(ConstrcutRGB(pixelR,pixelG,pixelB,lenPixel))
- newImage.save(newImg)
- print ("[*] Image <%s> cree : ok "%(newImg))
-
- def RetrouveValeur(pixel):
- buff = pixel[len(pixel)-1:]
- return buff
-
- def TrouveTexte(pixelR,pixelG,pixelB,lenPixel):
- decimal = ""
- i = 0
- while ( i < lenPixel ):
- decimal += RetrouveValeur(str(pixelR[i]))
- decimal += RetrouveValeur(str(pixelG[i]))
- decimal += RetrouveValeur(str(pixelB[i]))
- i += 1
- print ("[*] Decoupe valeur : ok .")
- decimal = str(decimal)
- i,compt = 0,0
- bheu = ""
- chiffreTxt = []
- while ( i < len(decimal) ):
- if ( compt == 3 ):
- chiffreTxt.append(bheu)
- bheu = ""
- compt = 0
- bheu += decimal[i]
- i += 1
- compt += 1
- i=0
- txt = ""
- while ( i < len(chiffreTxt) ):
- chiffre = int(chiffreTxt[i])
- chiffre = chiffre - 100
- txt += chr(chiffre)
- if ( "FiNiEnD" in txt ):
- break
- i += 1
- print ("Message -> %s"%(txt[:len(txt)-7]))
-
- def Acceuil():
- print """
- coder par Marnage
- Programme de steganogrphie ( lib : PIL )
- Cacher du texte dans une image (.bmp)
-
- Argument :
- -cache = pour cacher du texte dans une nouvelle image
- -i nomimage.bmp = l image de base ou sera cacher le texte
- -n newimage.bmp = la nouvelle image qui sera cree avec le texte
-
- -trouve = pour retrouver le texte
- -i = image dans la qu elle chercher le texte
-
- """
-
- def main(arg):
- Acceuil()
- if ( len(arg) != 3 and len(arg) != 5 ):
- print ("[!] Erreur : argument !")
- exit()
- i = 0
- while ( i < len(arg) ):
- if ( arg[i] == "cache" ):
- mode = "cache"
- elif ( arg[i] == "trouve"):
- mode = "trouve"
- elif ( arg[i] == "-i" ):
- nomImage = arg[i+1]
- elif ( arg[i] == "-n" ):
- NI = arg[i+1]
- i += 1
- if ( mode != "cache" and mode != "trouve" ):
- print ("[!] Erreur : argument !")
- exit()
- if not ".bmp" in nomImage :
- print("[!] Erreur : extention image non .bmp !")
- exit()
-
- if ( mode == "cache") :
- decimal = ConverCharInt()
-
- if ( access(nomImage, F_OK) ):
- image = open(nomImage)
- size = image.size
- print ("[*] Access/Ouverture image : ok .")
- else :
- print ("[!] Erreur : image innaccesible ! ")
- exit()
- pixelColor = list(image.getdata())
- lenPixel = len(pixelColor)
- i = 0
- pixelR = []
- pixelG = []
- pixelB = []
- lenPixel = len(pixelColor)
- size = image.size
-
- while ( i < lenPixel ):
- iP = 0
- pixelRGB = pixelColor[i]
- while ( iP < 3 ):
- if ( iP == 0 ):
- pixelR.append(pixelRGB[iP])
- elif ( iP == 1 ):
- pixelG.append(pixelRGB[iP])
- elif ( iP == 2 ):
- pixelB.append(pixelRGB[iP])
- iP += 1
- i += 1
- print ("[*] Separe RGB liste : ok .")
-
- if ( mode == "cache" ):
- CacheTexte(pixelR,pixelG,pixelB,decimal,lenPixel,size,NI)
-
- elif ( mode == "trouve" ):
- TrouveTexte(pixelR,pixelG,pixelB,lenPixel)
-
-
- if ( __name__ == "__main__" ):
- main(argv[1:])
#!/usr/bin/python
# -*- coding: iso8859-1 -*-
from Image import open,new
from sys import argv,exit
from os import access,F_OK
from string import split
def ConstrcutRGB(pixelR,pixelG,pixelB,lenP):
i = 0
pixel = []
while ( i < lenP ):
pixel.append((pixelR[i],pixelG[i],pixelB[i])) # (( )) Car on fait une liste de tuple
i += 1
print ("[*] Rassemble RGB -> liste -> tuple : ok .")
return pixel
def ConverCharInt():
txt = raw_input("Texte -> ")
txt += "FiNiEnD"
chiffreTexte,i = [],0
decimal = []
while ( i < len(txt) ):
chiffreTexte.append(ord(txt[i])+100)
i += 1
i = 0
i2 = 0
while ( i < len(chiffreTexte) ) :
i2 = 0
buff = str(chiffreTexte[i])
while ( i2 < len(buff) ):
decimal.append(buff[i2])
i2 += 1
i += 1
return decimal
def ModifValeurPixel(pixel,valeur):
if ( pixel > 245 ):
pixel[i] = 244
buff = str(pixel)
buff = buff[:len(buff)-1]
buff = buff+str(valeur)
pixel = buff
return pixel
def CacheTexte(pixelR,pixelG,pixelB,decimal,lenPixel,size,newImg):
i=0
i_d=0
while ( i < lenPixel ):
pixelR[i] = ModifValeurPixel(pixelR[i],decimal[i_d])
i_d += 1
if ( i_d == len(decimal) ):
break
pixelG[i] = ModifValeurPixel(pixelG[i],decimal[i_d])
i_d += 1
if ( i_d == len(decimal) ):
break
pixelB[i] = ModifValeurPixel(pixelB[i],decimal[i_d])
i_d += 1
if ( i_d == len(decimal) ):
break
i += 1
print("[*] Modifie valeur : ok ")
i = 0
while ( i < lenPixel ):
pixelR[i] = int(pixelR[i])
pixelG[i] = int(pixelG[i])
pixelB[i] = int(pixelB[i])
i += 1
newImage = new('RGB',size)
newImage.putdata(ConstrcutRGB(pixelR,pixelG,pixelB,lenPixel))
newImage.save(newImg)
print ("[*] Image <%s> cree : ok "%(newImg))
def RetrouveValeur(pixel):
buff = pixel[len(pixel)-1:]
return buff
def TrouveTexte(pixelR,pixelG,pixelB,lenPixel):
decimal = ""
i = 0
while ( i < lenPixel ):
decimal += RetrouveValeur(str(pixelR[i]))
decimal += RetrouveValeur(str(pixelG[i]))
decimal += RetrouveValeur(str(pixelB[i]))
i += 1
print ("[*] Decoupe valeur : ok .")
decimal = str(decimal)
i,compt = 0,0
bheu = ""
chiffreTxt = []
while ( i < len(decimal) ):
if ( compt == 3 ):
chiffreTxt.append(bheu)
bheu = ""
compt = 0
bheu += decimal[i]
i += 1
compt += 1
i=0
txt = ""
while ( i < len(chiffreTxt) ):
chiffre = int(chiffreTxt[i])
chiffre = chiffre - 100
txt += chr(chiffre)
if ( "FiNiEnD" in txt ):
break
i += 1
print ("Message -> %s"%(txt[:len(txt)-7]))
def Acceuil():
print """
coder par Marnage
Programme de steganogrphie ( lib : PIL )
Cacher du texte dans une image (.bmp)
Argument :
-cache = pour cacher du texte dans une nouvelle image
-i nomimage.bmp = l image de base ou sera cacher le texte
-n newimage.bmp = la nouvelle image qui sera cree avec le texte
-trouve = pour retrouver le texte
-i = image dans la qu elle chercher le texte
"""
def main(arg):
Acceuil()
if ( len(arg) != 3 and len(arg) != 5 ):
print ("[!] Erreur : argument !")
exit()
i = 0
while ( i < len(arg) ):
if ( arg[i] == "cache" ):
mode = "cache"
elif ( arg[i] == "trouve"):
mode = "trouve"
elif ( arg[i] == "-i" ):
nomImage = arg[i+1]
elif ( arg[i] == "-n" ):
NI = arg[i+1]
i += 1
if ( mode != "cache" and mode != "trouve" ):
print ("[!] Erreur : argument !")
exit()
if not ".bmp" in nomImage :
print("[!] Erreur : extention image non .bmp !")
exit()
if ( mode == "cache") :
decimal = ConverCharInt()
if ( access(nomImage, F_OK) ):
image = open(nomImage)
size = image.size
print ("[*] Access/Ouverture image : ok .")
else :
print ("[!] Erreur : image innaccesible ! ")
exit()
pixelColor = list(image.getdata())
lenPixel = len(pixelColor)
i = 0
pixelR = []
pixelG = []
pixelB = []
lenPixel = len(pixelColor)
size = image.size
while ( i < lenPixel ):
iP = 0
pixelRGB = pixelColor[i]
while ( iP < 3 ):
if ( iP == 0 ):
pixelR.append(pixelRGB[iP])
elif ( iP == 1 ):
pixelG.append(pixelRGB[iP])
elif ( iP == 2 ):
pixelB.append(pixelRGB[iP])
iP += 1
i += 1
print ("[*] Separe RGB liste : ok .")
if ( mode == "cache" ):
CacheTexte(pixelR,pixelG,pixelB,decimal,lenPixel,size,NI)
elif ( mode == "trouve" ):
TrouveTexte(pixelR,pixelG,pixelB,lenPixel)
if ( __name__ == "__main__" ):
main(argv[1:])
Conclusion
Historique
- 04 décembre 2007 02:14:03 :
- *
Sources de la même categorie
Commentaires
Discussions en rapport avec ce code source
|
CalendriCode
| | | L | M | M | J | V | S | D |
| | 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | | | |
|
Téléchargements
Logiciels à télécharger sur le même thème :
|
|