Esempio n. 1
0
def decProcess(decfile,img,emkey,out_f,cframe,nframe):
	print('[INFO] LOADING MAGE')
	in_im = cv2.imread(img)
	print('[INFO] IMAGE LOADED SUCCESSFULLY.')
	stegano = Steganography(in_im,emkey)
	print('[INFO] GETTING RECIEVER\'S UID.')
	ruid = stegano.extract_receiver()
	print('[INFO] RECIEVER\'S UID : {}.'.format(ruid))
	print('[INFO] INITIATING FACICAL RECOGNITION PROCESS.')
	
	if(auth(ruid)):
		print('[INFO] RECIEVER AUTHORIZED.')
		print('[INFO] EXTRACTING KEY FROM IMAGE.')
		byte_lst = stegano.decode_data()
		key = bytes(byte_lst)
		print('[INFO] KEY EXTRACTED SUCCESSFULLY.')
		print('[INFO] INITIATING DECRYPTION PROCESS.')
		dec = Decryption(decfile)
		try:
			dec.decrypt_data(key,out_f)
		except:
			print('[INFO] USER NOT AUTHORIZED. CHECK KEY.')
			tkinter.messagebox.showinfo("ERROR", "KEY ERROR. PLEASE CHECK IMAGE OR EMBEDDING KEY.")
		else:
			print('[INFO] DECRYPTION COMPLETED SUCCESSFULLY.')
			tkinter.messagebox.showinfo("Success", "DECRYPTED FILE SAVED.")
		
	else:
		print('[INFO] IDENTITY OF RECIEVER NOT VERIFIED.')
		tkinter.messagebox.showinfo("ERROR", "RECIEVER NOT AUTHORIZED.")
		
	showPrev(cframe,nframe)
Esempio n. 2
0
def main():
    '''
    Main function to handle the script

    @return : None
    '''
    args = handleArgs()
    cypher = Cypher(args.key,
                    args.size)  # create the Cypher obj from our Cypher class
    steganography = Steganography(
        args.imageInput, args.compression
    )  # create the Steganography obj from our Steganography class

    if args.decrypt:  # if decrypt option is used
        encoded = steganography.decode(
        )  # decode the message hidden into image
        result = cypher.decrypt(encoded)  # decrypt the message found

        # Write the decrypted message in the output file
        with open(args.dataOutput, 'wb') as writeFile:
            byteArray = bytearray(result)
            writeFile.write(byteArray)
    else:  # if encrypt option is used
        # Read bytes of input file
        with open(args.dataInput, 'rb') as readFile:
            data = [i for i in readFile.read()]
            encoded = cypher.encrypt(data)  # encrypt the message
            image = steganography.encode(
                encoded)  # encode the message into image
            '''
            Copy the encoded image to a new file in best quality
            to ensure that image's bits are not corrupted by compression
            '''
            image.save(args.imageOutput, quality=100)
Esempio n. 3
0
    def test_embedHorizontalExtractVertical(self):
        """
        Test that trying to extract a horizontal message using a vertical scan, produces an exception.
        """
        sourcePath = 'files/lena_full_h' + self.ext

        medium = Steganography(sourcePath, direction='vertical')
        message = medium.extractMessageFromMedium()

        self.assertEqual(message, None)
Esempio n. 4
0
    def test_embedVerticalExtractHorizontal(self):
        """
        Test that trying to extract a vertical message using a horizontal scan, produces an exception.
        """
        sourcePath = 'files/mona_small_v' + self.ext

        medium = Steganography(sourcePath)
        message = medium.extractMessageFromMedium()

        self.assertEqual(message, None)
Esempio n. 5
0
    def test_badSavingColorImageToText(self):
        """
        Test that trying to save a color image as a text produces an exception.
        """
        sourcePath = 'files/nature_sunflower_v' + self.ext

        medium = Steganography(sourcePath, direction='vertical')
        message = medium.extractMessageFromMedium()

        self.assertRaises(TypeError, message.saveToTextFile,
                          self.targetImageFilePath)
Esempio n. 6
0
    def test_badSavingTextToGrayImage(self):
        """
        Test that trying to save a text file as an image produces an exception.
        """
        sourcePath = 'files/mona_small_h' + self.ext

        medium = Steganography(sourcePath)
        message = medium.extractMessageFromMedium()

        self.assertRaises(TypeError, message.saveToImage,
                          self.targetTextFilePath)
Esempio n. 7
0
    def test_badSavingGrayImageToText(self):
        """
        Test that trying to save a gray-scale image as a text produces an exception.
        """
        sourcePath = 'files/bridge_dog_h' + self.ext

        medium = Steganography(sourcePath)
        message = medium.extractMessageFromMedium()

        self.assertRaises(TypeError, message.saveToTextFile,
                          self.targetImageFilePath)
Esempio n. 8
0
    def test_embedLargeMessageInSmallMedium(self):
        """
        Test that trying to embed a large message in medium, produces an exception.
        """
        sourcePath = 'files/sunflower' + self.ext
        mediumPath = 'files/mona' + self.ext

        message = Message(filePath=sourcePath, messageType='ColorImage')
        medium = Steganography(mediumPath)

        self.assertRaises(ValueError, medium.embedMessageInMedium, message,
                          self.targetImageFilePath)
Esempio n. 9
0
def encode_stegano(sc_data,uid):
	os.system('clear')
	print('Starting Steganography Encoding Process')
	in_f = input('Source image (should be .png format)\t: ')
	key = input('Steganography Encoding key (Caution: sensitive information)\t: ')
	in_im = cv2.imread(in_f)
	stegano = Steganography(in_im,key)
	res_img = stegano.encode_data(sc_data,uid)
	print('AES Encryption key successfully embedded into the image.')
	out_f = input('Encoded image (should be .png format)\t: ')
	cv2.imwrite(out_f,res_img)
	print('Updated image saved.')
	ip = input('Press any key to continue...')
Esempio n. 10
0
    def test_extractGrayImageVertical(self):
        """
        Test the extraction of a gray-scale in a medium, using a vertical raster scan.
        """
        sourcePath = 'files/bridge_dog_v' + self.ext
        expectedPath = 'files/dog' + self.ext

        medium = Steganography(sourcePath, direction='vertical')
        message = medium.extractMessageFromMedium()
        message.saveToTarget(self.targetImageFilePath)

        actualImage, expectedImage = loadTwoImageFiles(
            self.targetImageFilePath, expectedPath)

        self.assertEqual(actualImage, expectedImage)
Esempio n. 11
0
    def test_extractColorImageVertical(self):
        """
        Test the extraction of a color in a medium, using a vertical raster scan.
        """
        sourcePath = 'files/nature_sunflower_v' + self.ext
        expectedPath = 'files/sunflower' + self.ext

        medium = Steganography(sourcePath, direction='vertical')
        message = medium.extractMessageFromMedium()
        message.saveToTarget(self.targetImageFilePath)

        actualImage, expectedImage = loadTwoImageFiles(
            self.targetImageFilePath, expectedPath)

        self.assertEqual(actualImage, expectedImage)
Esempio n. 12
0
def encProcess(ruid,encfile,enc_opf,img,emkey,out_f,cframe,nframe):
	print('[INFO] STARTING ENCRYPTION PROCESS.')
	encrytor = Encryption(encfile)
	enc_key = encrytor.encrypt_data(enc_opf)
	print('[INFO] ENCRYPTION COMPLETED SUCCESSFULLY.')
	print('[INFO] LOADING SOURCE IMAGE')
	in_im = cv2.imread(img)
	print('[INFO] SOURCE IMAGE LOADED SUCCESSFULLY.')
	print('[INFO] STARTING STEGANOGRAPHY PROCESS.')
	stegano = Steganography(in_im,emkey)
	res_img = stegano.encode_data(enc_key,ruid)
	cv2.imwrite(out_f,res_img)
	print('[INFO] STEGANOGRAPHY PROCESS COMPLETED SUCCESSFULLY.')
	tkinter.messagebox.showinfo("Success", "Encrypted File and Steganographied Image Saved.")
	showPrev(cframe,nframe)
Esempio n. 13
0
    def test_extractLongTextVertical(self):
        """
        Test the extraction of a long text file in a medium, using a vertical raster scan.
        """
        sourcePath = 'files/lena_full_v' + self.ext
        expectedPath = 'files/full.txt'

        medium = Steganography(sourcePath, direction='vertical')
        message = medium.extractMessageFromMedium()
        message.saveToTarget(self.targetTextFilePath)

        actualTextFile, expectedTextFile = loadTwoTextFiles(
            self.targetTextFilePath, expectedPath)

        self.assertEqual(actualTextFile, expectedTextFile)
Esempio n. 14
0
    def test_extractShortTextHorizontal(self):
        """
        Test the extraction of a short text file in a medium, using a horizontal raster scan.
        """
        sourcePath = 'files/mona_small_h' + self.ext
        expectedPath = 'files/small.txt'

        medium = Steganography(sourcePath)
        message = medium.extractMessageFromMedium()
        message.saveToTarget(self.targetTextFilePath)

        actualTextFile, expectedTextFile = loadTwoTextFiles(
            self.targetTextFilePath, expectedPath)

        self.assertEqual(actualTextFile, expectedTextFile)
Esempio n. 15
0
    def test_embedLongTextHorizontal(self):
        """
        Test the embedding of a long text file in a medium, using a horizontal raster scan.
        """
        sourcePath = 'files/full.txt'
        expectedPath = 'files/lena_full_h' + self.ext
        mediumPath = 'files/lena' + self.ext

        message = Message(filePath=sourcePath, messageType='Text')
        medium = Steganography(mediumPath)
        medium.embedMessageInMedium(message, self.targetImageFilePath)

        actualImage, expectedImage = loadTwoImageFiles(
            self.targetImageFilePath, expectedPath)

        self.assertEqual(actualImage, expectedImage)
Esempio n. 16
0
    def test_embedShortTextVertical(self):
        """
        Test the embedding of a short text file in a medium, using a vertical raster scan.
        """
        sourcePath = 'files/small.txt'
        expectedPath = 'files/mona_small_v' + self.ext
        mediumPath = 'files/mona' + self.ext

        message = Message(filePath=sourcePath, messageType='Text')
        medium = Steganography(mediumPath, direction='vertical')
        medium.embedMessageInMedium(message, self.targetImageFilePath)

        actualImage, expectedImage = loadTwoImageFiles(
            self.targetImageFilePath, expectedPath)

        self.assertEqual(actualImage, expectedImage)
Esempio n. 17
0
    def test_embedGrayImageVertical(self):
        """
        Test the embedding of a gray-scale image in a medium, using a vertical raster scan.
        """
        sourcePath = 'files/dog' + self.ext
        expectedPath = 'files/bridge_dog_v' + self.ext
        mediumPath = 'files/bridge' + self.ext

        message = Message(filePath=sourcePath, messageType='GrayImage')
        medium = Steganography(mediumPath, direction='vertical')
        medium.embedMessageInMedium(message, self.targetImageFilePath)

        actualImage, expectedImage = loadTwoImageFiles(
            self.targetImageFilePath, expectedPath)

        self.assertEqual(actualImage, expectedImage)
Esempio n. 18
0
    def test_embedColorImageVertical(self):
        """
        Test the embedding of a color image in a medium, using a vertical raster scan.
        """
        sourcePath = 'files/sunflower' + self.ext
        expectedPath = 'files/nature_sunflower_v' + self.ext
        mediumPath = 'files/nature' + self.ext

        message = Message(filePath=sourcePath, messageType='ColorImage')
        medium = Steganography(mediumPath, direction='vertical')
        medium.embedMessageInMedium(message, self.targetImageFilePath)

        actualImage, expectedImage = loadTwoImageFiles(
            self.targetImageFilePath, expectedPath)

        self.assertEqual(actualImage, expectedImage)
Esempio n. 19
0
def decode_stegano():
	os.system('clear')
	print('Starting Steganography Decoding Process') 
	in_f = input('Encoded image (shoule be .png format)\t: ')
	in_im = cv2.imread(in_f)
	key = input('Steganography Encoding key (Caution: sensitive information)\t: ')
	stegano = Steganography(in_im,key)
	ruid = stegano.extract_receiver()
	print('meant for '+str(ruid))
	if(auth(ruid)):
		
		byte_lst = stegano.decode_data()
		data = bytes(byte_lst)
		return data
	else:
		print('not authorized')
		return None
Esempio n. 20
0
    def test_extractEncryptedText(self):
        """
        Test the extraction of an encrypted text file in a medium.
        """
        sourcePath = 'files/lena_full_enc' + self.ext
        expectedPath = 'files/full.txt'

        medium = Steganography(sourcePath)
        extractedMessage = medium.extractMessageFromMedium()

        encryptedMessage = AesMessage(extractedMessage, self.password)
        encryptedMessage.saveToTarget(self.targetTextFilePath)

        actualTextFile, expectedTextFile = loadTwoTextFiles(
            self.targetTextFilePath, expectedPath)

        self.assertEqual(actualTextFile, expectedTextFile)
Esempio n. 21
0
    def test_extractEncryptedColorImage(self):
        """
        Test the extraction of an encrypted color image `in a medium.
        """
        sourcePath = 'files/bridge_color_mona_enc' + self.ext
        expectedPath = 'files/color_mona' + self.ext

        medium = Steganography(sourcePath)
        extractedMessage = medium.extractMessageFromMedium()

        encryptedMessage = AesMessage(extractedMessage, self.password)
        encryptedMessage.saveToTarget(self.targetImageFilePath)

        actualImage, expectedImage = loadTwoImageFiles(
            self.targetImageFilePath, expectedPath)

        self.assertEqual(actualImage, expectedImage)
Esempio n. 22
0
    def test_embedEncryptedText(self):
        """
        Test the embedding of an encrypted text file in a medium.
        """
        sourcePath = 'files/full.txt'
        expectedPath = 'files/lena_full_enc' + self.ext
        mediumPath = 'files/lena' + self.ext

        message = Message(filePath=sourcePath, messageType='Text')
        encryptedMessage = AesMessage(message, self.password)

        medium = Steganography(mediumPath)
        medium.embedMessageInMedium(encryptedMessage, self.targetImageFilePath)

        actualImage, expectedImage = loadTwoImageFiles(
            self.targetImageFilePath, expectedPath)

        self.assertEqual(actualImage, expectedImage)
Esempio n. 23
0
    def test_embedEncryptedColorImage(self):
        """
        Test the embedding of an encrypted color image in a medium.
        """
        sourcePath = 'files/color_mona' + self.ext
        expectedPath = 'files/bridge_color_mona_enc' + self.ext
        mediumPath = 'files/bridge' + self.ext

        message = Message(filePath=sourcePath, messageType='ColorImage')
        encryptedMessage = AesMessage(message, self.password)

        medium = Steganography(mediumPath)
        medium.embedMessageInMedium(encryptedMessage, self.targetImageFilePath)

        actualImage, expectedImage = loadTwoImageFiles(
            self.targetImageFilePath, expectedPath)

        self.assertEqual(actualImage, expectedImage)