Skip to content

Instantly share code, notes, and snippets.

Created August 16, 2021 20:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import os, sys
from secretsharing import SecretSharer
import PySimpleGUI as sg
import json
from cryptosteganography import CryptoSteganography
import hashlib
from binascii import hexlify, unhexlify
def get_files(title):
event, values = sg.Window(title).Layout([[sg.Input(key='_FILES_'), sg.FilesBrowse()], [sg.OK(), sg.Cancel()]]).Read()
return values['_FILES_'].split(';')
def get_password(title):
password = sg.popup_get_text(
title, password_char='*')
return password
def get_text(title):
text = sg.popup_get_text(title)
return text
def stego_share_encrypt():
secretMessage = get_text("Enter Your Secret Message:")
threshold = get_text("Enter Key Threshold Number:")
numberOfKeys = get_text("Enter Number of Keys:")
filename = get_files("Hold Shift and Choose "+str(numberOfKeys)+" PNG/JPG images:")
password = get_password("Create a Master Password:")
os.makedirs('shares', exist_ok=True)
print(secretMessage, password, threshold, numberOfKeys, filename)
shares = SecretSharer.split_secret(bytes.hex(bytes(secretMessage.encode())), int(threshold), int(numberOfKeys))
for count, key in enumerate(shares):
print(count, key)
status = hide_message(key,filename[count],"shares/"+os.path.basename(filename[count]), password)
sg.popup("Created "+numberOfKeys+" keys with a threshold min of "+threshold+" keys required.")
#stegokey = json.loads(lsb.reveal("221blogo.png"))
def stego_share_decrypt():
files = get_files("Hold shift and select files:")
password = get_password("Enter your master password:")
shares = []
for file in files:
secret = bytes.fromhex(SecretSharer.recover_secret(shares))
sg.popup("Your secret is", secret.decode())
except UnicodeDecodeError:
sg.popup("Your secret is", secret)
sg.popup("Your secret is", hexlify(secret))
return secret
def hide_message(message, originalfile, outputfile, password):
crypto_steganography = CryptoSteganography(password)
crypto_steganography.hide(originalfile, outputfile, message)
return {'status': True, 'filename': outputfile, "password": password, 'secret_size': len(message)}
def reveal_message(image_filename, password=None):
crypto_steganography = CryptoSteganography(password)
return crypto_steganography.retrieve(image_filename)
secret = stego_share_decrypt()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment