Beispiel #1
0
def main():

	# Check that the necessary command line arguments were provided.
	if len(sys.argv) != 4:
		utils.log('ERROR: incorrect syntax')
		printUsage()
		return -1

	# Store command line arguments for later.
	imgFilename = sys.argv[2]
	msgFilename = sys.argv[3]

	# Decide if we have to encode or decode:
	if sys.argv[1] == '-e':
		utils.log('Encoding...')
		if encodeAlgorithm(imgFilename, msgFilename, utils.DEFAULT_ENCODE_OUTPUT) != utils.ERROR_OK:
			utils.log('ERROR: there was a problem encoding the message')
			return -1
		else:
			utils.log('Encoding executed correctly')
			return 0
	elif sys.argv[1] == '-d':
		utils.log('Decoding...')
		if decodeAlgorithm(imgFilename, msgFilename) != utils.ERROR_OK:
			utils.log('ERROR: there was a problem decoding the message')
			return -1
		else:
			utils.log('Decoding executed correctly')
			return 0
	else:
		utils.log('ERROR: option "{}" not recognized'.format(sys.argv[1]))
		printUsage()
		return -1
Beispiel #2
0
	def runCompleteTest(self, imageFile, msgFile):

		# Remove garbage files if they are present
		try:
			os.remove(utils.DEFAULT_ENCODE_OUTPUT)
		except OSError:
			pass
		try:
			os.remove(utils.DEFAULT_DECODE_OUTPUT)
		except OSError:
			pass
		
		# Execute the tests.
		self.assertEqual(encodeAlgorithm(imageFile, msgFile, utils.DEFAULT_ENCODE_OUTPUT), utils.ERROR_OK)
		self.assertEqual(decodeAlgorithm(utils.DEFAULT_ENCODE_OUTPUT, utils.DEFAULT_DECODE_OUTPUT), utils.ERROR_OK)
		self.assertTrue(cmp(msgFile, utils.DEFAULT_DECODE_OUTPUT))

		# Remove garbage files again.
		try:
			os.remove(utils.DEFAULT_ENCODE_OUTPUT)
		except OSError:
			pass
		try:
			os.remove(utils.DEFAULT_DECODE_OUTPUT)
		except OSError:
			pass
Beispiel #3
0
	def test_PNG_BW_UTF8(self):
		utils.silent = True
		self.assertEqual(encodeAlgorithm('test_files/png_8l.png', 'test_files/txt_utf8.txt', utils.DEFAULT_ENCODE_OUTPUT), utils.ERROR_MSG_TOO_LARGE)
Beispiel #4
0
	def test_ASCII_huge(self):
		utils.silent = True
		self.runCompleteTest('test_files/jpg_huge.jpg', 'test_files/txt_ascii_huge.txt')
		self.assertEqual(encodeAlgorithm('test_files/png_8l.png', 'test_files/txt_ascii_huge.txt', utils.DEFAULT_ENCODE_OUTPUT), utils.ERROR_MSG_TOO_LARGE)
def encode(imgFilename, msgFilename, outputFilename):
    return encodeAlgorithm(imgFilename, msgFilename, outputFilename)