I know I just listed an earlier problem I had with the encoder program, but now I am having trouble placing the decoding formula into the decoding program. In the program you will see that I have the normal decoder for the ASCII characters in there. everytime I try to change it to say:

decodedMessage = (numericMessage + 5) / 6 (This is the reverse of the encoding)

it comes up with an error: "TypeError: Can't convert 'int' object to str implicitly"

its really frustrating, I am just a beginner not even halfway through the class, so forgive me. I have been on it for hours trying to figure it out myself
Basically it needs to read from a file that has a list of numbers from an encoding program that needs to be read and split() so the decoded can assign the letter originally assigned to the ASCII value. Obviously somewhere in there I need to incorporate the formula to get it back to the original number to convert...

def main():

    #Declare and initialize variables
    #string numericMessage, decodedMessage
    numericMessage = decodedMessage = ""
    numericValue = 0
    

    #Intro
    print(" _____                       _                ______                                   _") 
    print("(____ \                     | |              (_____ \                                 | |")
    print(" _   \ \ ____ ____  ___   _ | | ____  ____    _____) )____ ___   ____  ____ ____ ____ | |")
    print("| |   | / _  ) ___)/ _ \ / || |/ _  )/ ___)  |  ____// ___) _ \ / _  |/ ___) _  |    \|_|")
    print("| |__/ ( (/ ( (___| |_| ( (_| ( (/ /| |      | |    | |  | |_| ( ( | | |  ( ( | | | | |_ ")
    print("|_____/ \____)____)\___/ \____|\____)_|      |_|    |_|   \___/ \_|| |_|   \_||_|_|_|_|_|")
    print("                                                               (_____|                   ")
    print("\n\n")

    #Open file "encryptedmessage.txt"
    infile = open("encryptedmessage.txt","r")

    #Read in file line1
    numericMessage = infile.readline()


    #loop the split numericMessage
    for numStr in numericMessage.split():
        #convert the string value of the number to numericValue
        numericValue = eval(numStr)
        
        

        #Add the chr value of numericValue to decodedMessage
      
      
        decodedMessage = ((numericMessage) + 5) / 6
        


    

    print("Your decoded message is:\t",decodedMessage)
#loop the split numericMessage
    for numStr in numericMessage.split():
        #convert the string value of the number to numericValue
        numericValue = eval(numStr)
        
        #Add the chr value of numericValue to decodedMessage
      
        decodedMessage = decodedMessage +(chr(numericValue) + 5) / 6

put your formula at line 4 instead of line and better to use int function instead of eval. Naming of your variables does not follow the Python conventions (PEP8). If you are free to choose, follow them, it produce more readable code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.