0

I am trying to create a program that prints out ascii images from their respective external text files, The problem is the message has to be decrypted by shifting the characters to the left on the Ascii chart first,

def decrypt(cipherText, key):
    """ Decode a message by shifting characters to the left on the ASCII chart. """
    plainText = ""
    for character in cipherText:
        cipherValue = ord(character)
        ordValue = cipherValue - key
        plainText += chr(ordValue)
    return plainText

def main():
    if __name__ == "__main__":
        main()

sample of printed text file below(should print out toy story ascii image)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/;;;;;;;;;/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/;;;;;;;;;;;;;;;/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;;;;;;;;;;;;;;;;;;;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;;;;;;;;;;;;;;;;;;;;;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;!!a;;;;;;;;;;;;;;;;;;;;;!!!!!!!!!!!!!!!!!!!!!!!!!!!!;;!?/!a;;;;;;;;;;;;;;;(((!!/;;!!!!!!!!!!!!!!!!!!!!!!!!!!!!;;!a=D?-//aaaaaaaa///!!!/;;((!!!!!!!!!!!!!!!!!!!!!!!!!!!!a;;;//aa===DDD???((//;;;((/!!!!!!!!!!!!!!!!!!!/-d%%i/!!!!a(;;;;;;/////;;;((((/-d%%M!!!!!!!!!!!!!!!!!!K%%%%%/@/!-e%>!!aaaaa/-!!!/{dd%%%%%%%%/!!!!!!!!!!!!!!!!-%%%%%%%G/#5Q#/;a;;!-%%#/;;;/!#%%%%%%%%%i!!!-dd-!!!!!!!!!!!!!!!-%%%%%Q#/-Q/#!((-d!a-e%%!a(aa(;/a%%%%%%%%%i!>#4%%d/!!!!!!!!!!!!!!/%%%%%G!%%#!ed!.@##@!@%%(-d%%d!!a!@%%%%%%%%G-!e%%%%i/!!!!!!!!!!!!!!K%%%%%%!%G!-%(-##%%i/@%(----/##!/!a%%%%%%%%!e!4%%%%%%/!!!!!!!!!!!!!!4%%%%%Q!%G!%%!!!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ps!wjtjujoh!iuuqt;00btdjjbsu/xfctjuf0Uijt!BTDJJ!qjd!dbo!cf!gpvoe!buiuuqt;00btdjjbsu/xfctjuf0joefy/qiq@bsu>npwjft0upz&31tupsz `

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
  • It looks like ASCII art, but you're missing the newlines. Does the input string have newlines? – Tim Roberts Oct 02 '22 at 18:42
  • Welcome to Stack Overflow. "The problem is the message has to be decrypted by shifting the characters to the left on the Ascii chart first" That isn't a problem, it's a **task**. A **problem** is something that went wrong when you tried to use your code, which is then something you can **ask a question** about. Please read [ask] and ask the question. That said, there are multiple problems with how the code is set up. I will try to give relevant duplicate links. – Karl Knechtel Oct 02 '22 at 18:47
  • What went wrong? Show us the traceback. You have a function `def main():` that calls itself, which would be a recursion error. Except its not called on script execution, so nothing happens. – tdelaney Oct 02 '22 at 18:50

0 Answers0