Ejemplo n.º 1
0
def decode(openPath, mapSeed, password="", zeroTerm=True, file=None):
	"""decode data from an text file using homoglyphs

	Args:
		openPath (string): path to the stego-text file to decode
		mapSeed (string): seed to generate the lsb map
		password (str, optional): password to encrypt the data with. Defaults to "".
		zeroTerm (boolean, optional): stop decoding on \x00 (NUL). Defaults to True.
		file (<file>, optional): file pointer. Defaults to None.

	Returns:
		bytes: data from the text file
	"""
	with open(openPath, encoding="utf-8") as openData:
		fileData = openData.read()
	position = 0
	data = []
	decodeMap = getMap(fileData, mapSeed)
	for _char in fileData:
		byte = 0
		shift = 0
		while shift < 8:
			if decodeMap[position] > 0:
				byte, shift = decodeGlyph(fileData, position, byte, shift)
			position += 1
		if byte == 0 and zeroTerm:
			break
		data.append(byte)
	result = otp(bytes(data), password, False)
	return toFile(result, file) if file else result
Ejemplo n.º 2
0
def encode(openPath, writePath, data, mapSeed, password=""):
	"""encode a text file with data using homoglyphs

	Args:
		openPath (string): path to the original text file to open
		writePath (string): path to write the stego-text file
		data (string): data to encode
		mapSeed (string): seed to generate the lsb map
		password (str, optional): password to encrypt the data with. Defaults to "".
	"""
	with open(openPath, encoding="utf-8") as openData:
		fileData = openData.read()
	position = 0
	output = []
	data = otp(toBin(data), password) + b"\x00"
	encodeMap = getMap(fileData, mapSeed)
	systemRandom = SystemRandom()
	for char in data:
		shift = 0
		while shift < 8:
			if encodeMap[position] > 0:
				result, shift = encodeGlyph(fileData, position, char, shift)
			else:
				result, _shift = encodeGlyph(fileData, position,
				systemRandom.randint(0, 1) << shift, shift)
			output.append(result)
			position += 1
	output.append(fileData[position:])
	with open(writePath, "w", encoding="utf-8") as writeData:
		writeData.write("".join(output))
Ejemplo n.º 3
0
    def decode(self, mapSeed, password="", zeroTerm=True, file=None):
        """decode data from an array using lsb steganography

		Args:
		mapSeed (string): seed to generate the lsb map
		password (str, optional): password to encrypt the data with. Defaults to "".
		zeroTerm (boolean, optional): stop decoding on \x00 (NUL). Defaults to True.
		file (<file>, optional): file pointer. Defaults to None.

		Returns:
		bytes: data from the image
		"""
        lsbMap = getMap(self.array, mapSeed)
        data = []
        while self.pointer in range(self.arrayLen):
            byte = 0
            shift = 0
            while shift < 8:
                if lsbMap[self.pointer] > 0:
                    bit = self.getLsb()  # Little endian
                    byte += bit << shift
                    shift += 1
                else:
                    self.pointer += 1  # Increment pointer anyway
            if byte == 0 and zeroTerm:
                break
            data.append(byte)
        result = otp(bytes(data), password, False)
        return toFile(result, file) if file else result
Ejemplo n.º 4
0
def encode(openPath, writePath, data, mapSeed, password="", safe=True):
    """encode a text file with data using zero width chars

	Args:
		openPath (string): path to the original text file to open
		writePath (string): path to write the stego-text file
		data (string|bytes|<file>): data to encode
		mapSeed (string): seed to generate the lsb map
		password (str, optional): password to encrypt the data with. Defaults to "".
		safe (boolean, optional): use a reduced set of chars to show in fewer
		editors. Defaults to True.
	"""
    with open(openPath, "rb") as openData:
        fileData = openData.read()
    position = 0
    pointer = 0
    zwcMap = getMap(fileData, mapSeed)
    encodeData = otp(toBin(data), password) + b"\x00"
    while pointer < len(encodeData):
        if zwcMap[position] > 0:
            position, fileData = encodeCharZero(fileData, position,
                                                encodeData[pointer], safe)
            pointer += 1
        else:
            position += getUtf8Size(fileData,
                                    position)[0]  # increment by char size
    with open(writePath, "wb") as writeData:
        writeData.write(fileData)
Ejemplo n.º 5
0
    def encode(self, mapSeed, password=""):
        """encode an array with data using lsb steganography

		Args:
		mapSeed (string): seed to generate the lsb map
		password (str, optional): password to encrypt the data with. Defaults to "".
		"""
        data = otp(self.data, password) + b"\x00"
        lsbMap = getMap(self.array, mapSeed)
        systemRandom = SystemRandom()
        for char in data:
            shift = 0
            while shift < 8:
                if lsbMap[self.pointer] > 0:
                    self.setLsb(char >> shift & 1)
                    shift += 1
                else:
                    self.setLsb(systemRandom.randint(0, 1))
        return self.array
Ejemplo n.º 6
0
def decode(openPath,
           mapSeed,
           password="",
           zeroTerm=True,
           file=None,
           safe=True):
    """decode data from a text file using zero width chars

	Args:
		openPath (string): path to the stego-text file to decode
		mapSeed (string): seed to generate the lsb map
		password (str, optional): password to encrypt the data with. Defaults to "".
		zeroTerm (boolean, optional): stop decoding on \x00 (NUL). Defaults to True.
		file (<file>, optional): file pointer. Defaults to None.
		safe (boolean, optional): use a reduced set of chars to show in fewer
		editors. Defaults to True.

	Returns:
		bytes: data from the text file
	"""
    with open(openPath, "rb") as openData:
        fileData = openData.read()
    position = 0
    data = []
    zwcMap = getMap(fileData, mapSeed)
    for _char in fileData:
        if zwcMap[position] > 0:
            position, byte = decodeCharZero(fileData, position, safe)
            if byte == 0 and zeroTerm:
                break
            data.append(byte)
        else:
            position += getUtf8Size(fileData,
                                    position)[0]  # increment by char size
    result = otp(bytes(data), password, False)
    return toFile(result, file) if file else result