-2

Hi there i am trying to put a user input into an array, so far i have:

#Decrypt string
def decrypt():
    print("Please enter code to be decrypted.")
    text = input(">>>")
    print("Please enter your key used to encrypt the data.")
    key = int(input(">>>"))



    #Put input into array
    #????

I am tring to get the input and put it in an array so that it can be referenced using

chr(text[1])

To convert it into plain text from ascii (Basic encryption and decryption). I have found a few posts on this but they are outdated (for python2 etc...).

Thanks!

Dleep
  • 1,045
  • 5
  • 12
aidan
  • 23
  • 1
  • 7

1 Answers1

0

If you just want to have an indexable list to store user inputs as they come in, you can use the built-in list class and its append method:

keys = list();
texts = list();

def decrypt():
  print("Please enter code to be decrypted.")
  text = input(">>>")
  print("Please enter your key used to encrypt the data.")
  key = int(input(">>>"))
  texts.append(text)
  keys.append(key)

Now, texts[n] will return the nth text value entered by your user.

Luc125
  • 5,752
  • 34
  • 35
  • Sorry i didn't see this but i just used `text1 = text.split()` since the input comes with spaces and it works a charm, thanks though! – aidan Jun 18 '16 at 07:02