ValueError: invalid literal for int() with base 10: when it worked before

2024/11/14 13:06:09

I'm having some issues with my program, basically what I'm trying to do is Stenography, insert an image into another image and then extract the secret image.

My program is able to insert just fine, but extracting it I get this error.

enter image description here

It was working fine the other day, I was able to read and write perfectly. I am also using the same BMP images as the other day as well. Anyone know the issue? I didn't change any of the code from it's working state, I even uploaded to github to make sure that version worked.

There are 3 files of code that is on my github.

https://github.com/am3ience/Steganography/blob/master/dcstego.py

https://github.com/am3ience/Steganography/blob/master/dcimage.py

https://github.com/am3ience/Steganography/blob/master/dcutils.py

The problem seems to be happening in dcutils.py in my read function. Any help would be amazing, i'm stumped.

#examine the lsb of each pixel, grouping into bytes
#check for nulls to signify if we are dealing with data or header info
#bytes determined to be data result in the hidden file
#---------------------------------------------------------------
def read(mainimage, output, password):lsbByte_Array = []dataString = ""secretFileName = ""lsbString = ""count = 0#iteratorheaderReceived=0#flagssizeReceived=0imageObject = dcimage.openFile(mainimage)pixels = imageObject.load()imageWidth, imageHeight = imageObject.size#cycle through each pixelfor x in range(imageWidth):for y in range(imageHeight):r, g, b = pixels[x, y]#trim so we are dealing with only the least significant bitredPixel = str(bin(r)[2:].zfill(8))[7]greenPixel = str(bin(g)[2:].zfill(8))[7]bluePixel = str(bin(b)[2:].zfill(8))[7]secretBits = [redPixel, greenPixel, bluePixel]#for each of rgbfor i in range(0,3):#check if our flags are setif (headerReceived == 0 or sizeReceived == 0):lsbString += secretBits[i]#verify each byteif len(lsbString) == 8:lsbByte_Array.append(lsbString)#check if we have received a NULL byteif lsbString == "00000000":if headerReceived == 0:#convert the the bit array into an ascii String#set flag when header and size was receivedfileName = ''.join(binascii.unhexlify('%x' % int(b,2)) for b in lsbByte_Array[0:len(lsbByte_Array) - 1])print "File name: " + str(fileName)headerReceived = 1elif sizeReceived == 0:fileSize = ''.join(binascii.unhexlify('%x' % int(b,2)) for b in lsbByte_Array[0:len(lsbByte_Array) - 1])print "File size: " + fileSizesizeReceived=1#reset the valueslsbByte_Array = []lsbString = ""#once headers received, resulting data is hidden dataelif (headerReceived == 1 and sizeReceived == 1):if int(count) < int(fileSize):#keep appending secret bits to the dataString until depleteddataString += secretBits[i]count += 1else:#send to have hidden file created
return dcimage.saveImage(output, dataString)
Answer
fileSize = ''.join(binascii.unhexlify('%x' % int(b,2)) for b in lsbByte_Array[0:len(lsbByte_Array) - 1])

if lsbByte_Array is an empty array then fileSize will be an empty string, which is obviously why int(fileSize) fails.

You should probably use a default value, for example

fileSize = ''.join(binascii.unhexlify('%x' % int(b,2)) for b in lsbByte_Array[0:len(lsbByte_Array) - 1]) or 0

As a side note, stuff like lsbByte_Array[0:len(lsbByte_Array) - 1]) can simply be written as lsbByte_Array[0:-1].

https://en.xdnf.cn/q/119472.html

Related Q&A

How to fetch the current branch from Jenkins?

I would like to query Jenkins using its API and Python to fetch the branch that is currently ready to be built.How can I do that?

How to vertically stretch graphs with matplotlib subplot [duplicate]

This question already has answers here:How do I change the size of figures drawn with Matplotlib?(16 answers)Closed 5 years ago.With the following code, I try to plot 12 different histograms in one pi…

Python Selenium Traceback (most recent call last):

Im trying to use selenium for a python web scraper but when I try to run the program I get the following error: "/Applications/Python 3.8/IDLE.app/Contents/MacOS/Python" "/Applications/P…

getting error while installing opencv via pip

python version = Python 3.8.0pip version = 19.3.1C:\Users\Sami Ullah Ch>pip3 install opencv-pythonERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none)

Check whether text contains x numbers in a row [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 8 years ago.Improve…

How to add polling interval for a GET request in python

I have a case where I have to keep checking the response of a GET call until I see the status as success in the api response. And it takes around 20 to 50 mins to get the status from active to success.…

Total beginner wrote a tic tac toe game in Python and would like some feedback

Ive decided to learn Python about 2 weeks ago, been going through various books and videos, and Ive decided to try my hand at programming a tic tac toe game. I was somewhat successful (it doesnt recogn…

Separating tag attributes as a dictionary

My entry (The variable is of string type): <a href="https://wikipedia.org/" rel="nofollow ugc">wiki</a>My expected output: { href: https://wikipedia.org/, rel: nofollow …

How can I remove duplication of 2 separate which is interrelated with each other (PYTHON)

After reading so many title, I couldnt solved the problem below. Does anyone can help me please ? For instance, I have 2 list (list_I and list_II) which is interrelated with each other. list_I = [123,…