-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSteg.py
75 lines (57 loc) · 2.67 KB
/
Steg.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import funciones
try:
from PIL import Image
except ImportError:
print("ERROR: Es necesario instalar 'PILLOW'\nPARA INSTALARLO PRUEBA: pip install pip")
import sys
menu = "STEG.PY\n -e)\t Para codificar el texto.\n steg.py -e ImagenEntrada -f|-s TextoEntrada ImagenSalida \n\n \t\t -f|--InputFile\t Si la cadena de texto se encuentra dentro de un archivo.\n \t\t -s|--InputString\t Si la cadena de texto se va a introducir directamente.\n\n-d)\t Para decodificar el texto.\n steg.py -d ImagenEncodeada -f|-s SalidaDelTexto \n\n \t\t -f|--OutputFile\t Si la salida se va a guardar en un archivo.\n \t\t -s|--OutputString\t Si la salida va a salir directamente por pantalla."
try:
argumento = sys.argv[1]
if argumento == '-e':
print("--------\nENCODE")
# ARGUMENTO 2, LA IMAGEN
imagenEntradaPng = sys.argv[2]
if funciones.CheckImagen(imagenEntradaPng):
imagen = Image.open(imagenEntradaPng)
#ARGUMENTOS 3 Y 4, EL TEXTO
procedenciaInput = sys.argv[3]
inputTexto = sys.argv[4]
if (procedenciaInput == "-f") or (procedenciaInput == "--InputFile"):
try:
textoClaro = open(inputTexto, 'r')
textoClaro = textoClaro.read()
print(" Texto claro correcto")
except FileNotFoundError:
print(f"[*] ERROR: El archivo '{inputTexto}' no se encuentra.")
exit()
elif (procedenciaInput == "-s") or (procedenciaInput == '--InputString'):
print(" Texto claro correcto.")
textoClaro = inputTexto
# ARGUMENTO 5, LA SALIDA
try:
imagenSalida = sys.argv[5]
if funciones.CheckFormat(imagenSalida):
pass
else:
print("[*] Lo sentimos, solo podemos procesar imagenes png.")
except IndexError:
print("[*] ERROR: No hay imagen de salida.")
exit()
funciones.HideText(imagenEntradaPng,textoClaro,imagenSalida)
elif argumento == '-d':
print("----\nDECODE")
imagen = sys.argv[2]
texto = funciones.Decode(imagen)
formaOut = sys.argv[3]
print("Aqui llega")
if (formaOut == "-f") or (formaOut == "--OutputFile"):
finalOut = sys.argv[4]
archivo = open(finalOut, "w")
archivo.write(texto)
elif (formaOut == "-s") or (formaOut == "--OutputString"):
print(f"EL TEXTO ES: {texto}")
else:
print("[*] ERROR: Argumento inválido.")
except IndexError:
print(menu)
exit()