0

This is my task: https://i.stack.imgur.com/qv6us.png

I have tried to get each item out of the ASCII list by using z as the list item so the program increases z by one every time I go through the for loop.

ciphertext = []
z=0
for item in messagelist:                    # messagelist a list of characters

If there is a space then I want to ignore it.

    if ' ' in messagelist:
        break

Then I want it to add the item to an integer:'offsetfactor'.

    else:                                   # ascii list is a list of ascii codes/integers
    y = asciilist[z] + offsetFactor     # offset factor is a randomly generated integer
    print (y)

Then if the answer is more than 126, I will minus 94 and turn the answer into an ASCII character. Then I want to append all the ASCII characters to a list and convert the list into a string.

    if y > 126:
        y = y - 94
        asciichar = str(chr(y))         # turns y into an ascii character
        ciphertext.append(asciichar)    # adds the ascii character to a list called ciphertext
    else:
        asciichar = str(chr(y))        
        ciphertext.append(asciichar)
    z+=1
encrypted = str(ciphertext)                # turns ciphertext into a string
print ('Your encrypted message is: ',encrypted)

This doesn't seem to be working as 'encrypted' is printed as an empty list. I will be grateful for any help as it took me ages even to write the question!

Quick
  • 11
  • 2
  • 3
    As it stands, this post is a story. I don't see a question. Please read [ask] and how to create a [MCVE]. – timgeb Jun 02 '18 at 11:26
  • 1
    And/or have a look a [this question](https://stackoverflow.com/questions/50607128/creating-a-nested-dictionary-from-a-flattened-dictionary) in order to get an idea what a good question looks like if you have trouble implementing an algorithm. – timgeb Jun 02 '18 at 11:31
  • Thanks! The first problem I see is that your `for` loop immediately terminates if there is a blank character in `messagelist`. You are not ignoring the space, you are terminating the complete algorithm if there is any space in `messagelist`. – timgeb Jun 02 '18 at 12:20
  • Don't provide information as image which can be text. – Kalle Richter Jun 02 '18 at 14:08
  • Just to clarify what @timgeb was saying, if you use `break` that means to exit the `for` loop. If what you want to do is just go straight to the next item in the list, you want to use `continue` instead of `break`. – Shiania White Jun 02 '18 at 19:12

0 Answers0