Python Forum
[split] Need help with lists to continue my assignment code
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Need help with lists to continue my assignment code
#1
(Oct-07-2016, 10:53 PM)tinabina22 Wrote: I'm using Python 3.5, Pycharm.

This is what the instructions say to do:

####### YOUR CODE HERE ######
#You will need to encrypt the password and store it in the list of passwords

#The encryption function is already written for you
#Step 1: You can say encryptedPassword = passwordEncrypt(unencryptedPassword,encryptionKey)]
#the encryptionKey variable is defined already as 16, don't change this
#Step 2: create a list of size 2, first item the website name and the second item the password.
#Step 3: append the list from Step 2 to the password list


This is what I have so far:

input = samplePasswordFile.append([website, encryptedPassword])

This is the error code I am getting with it:

input = samplePasswordFile.append([website, encryptedPassword])
NameError: name 'samplePasswordFile' is not defined



The code won't even read beyond that, so have no idea what:

encryptedPassword = passwordEncrypt(unencryptedPassword,encryptionKey)]

Is going to result in.

I need help with this same problem. Here is my code :
import csv
import sys
[i]#The password list - We start with it populated for testing purposes
passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]
#The password file name to store the passwords to
passwordFileName = "samplePasswordFile"
#The encryption key for the caesar cypher
encryptionKey=16
#Caesar Cypher Encryption
def passwordEncrypt (unencryptedMessage, key):
   #We will start with an empty string as our encryptedMessage
   encryptedMessage = ''
   #For each symbol in the unencryptedMessage we will add an encrypted symbol into the encryptedMessage
   for symbol in unencryptedMessage:
       if symbol.isalpha():
           num = ord(symbol)
           num += key
           if symbol.isupper():
               if num > ord('Z'):
                   num -= 26
               elif num < ord('A'):
                   num += 26
           elif symbol.islower():
               if num > ord('z'):
                   num -= 26
               elif num < ord('a'):
                   num += 26
           encryptedMessage += chr(num)
       else:
           encryptedMessage += symbol
   return encryptedMessage
def loadPasswordFile(fileName):
   with open(fileName, newline='') as csvfile:
       passwordreader = csv.reader(csvfile)
       passwordList = list(passwordreader)
   return passwordList
def savePasswordFile(passwordList, fileName):
   with open(fileName, 'w+', newline='') as csvfile:
       passwordwriter = csv.writer(csvfile)
       passwordwriter.writerows(passwordList)
while True:
   print("What would you like to do:")
   print(" 1. Open password file")
   print(" 2. Lookup a password")
   print(" 3. Add a password")
   print(" 4. Save password file")
   print(" 5. Print the encrypted password list (for testing)")
   print(" 6. Quit program")
   print("Please enter a number (1-4)")
   choice = input()
   if(choice == '1'): #Load the password list from a file
       passwords = loadPasswordFile(passwordFileName)
   if(choice == '2'): #Lookup at password
       print("Which website do you want to lookup the password for?")
       for keyvalue in passwords:
           print(keyvalue[0])
       passwordToLookup = input()
       ####### YOUR CODE HERE ######
       #You will need to find the password that matches the website
       #You will then need to decrypt the password
       #
       #1. Create a loop that goes through each item in the password list
       #  You can consult https://champlain.instructure.com/course...id=8842667
       #  simplest way to loop through a list is: for i in range(len(NAMEOFLIST))
       #
       #2. Check if the name is found.  To index a list of lists you use 2 square backet sets
       #   So passwords[0][1] would mean for the first item in the list get it's 2nd item (remember, lists start at 0)
       #   So this would be 'XqffoZeo' in the password list given what is predefined at the top of the page.
       #   If you created a loop using the syntax described in step 1, then i is your 'iterator' in the list so you
       #   will want to use i in your first set of brackets.
       #
       #3. If the name is found then decrypt it.  Decrypting is that exact reverse operation from encrypting.  Take a look at the
       # caesar cypher lecture as a reference.  You do not need to write your own decryption function, you can reuse passwordEncrypt
       #
       #  Write the above one step at a time.  By this I mean, write step 1...  but in your loop print out every item in the list
       #  for testing purposes.  Then write step 2, and print out the password but not decrypted.  Then write step 3.  This way
       #  you can test easily along the way.
       #
  [b]for i,item in enumerate(passwords):
   print("{}{}".format(i, item))[/b]

   if(choice == '3'):
       print("What website is this password for?")
       website = input()
       print("What is the password?")
       unencryptedPassword = input()
       ####### YOUR CODE HERE ######
       #You will need to encrypt the password and store it in the list of passwords
       #The encryption function is already written for you
       #Step 1: You can say encryptedPassword = passwordEncrypt(unencryptedPassword,encryptionKey)]
       #the encryptionKey variable is defined already as 16, don't change this
       #Step 2: create a list of size 2, first item the website name and the second item the password.
       #Step 3: append the list from Step 2 to the password list
       ####### YOUR CODE HERE ######
   if(choice == '4'): #Save the passwords to a file
           savePasswordFile(passwords,passwordFileName)
   if(choice == '5'): #print out the password list
       for keyvalue in passwords:
           print(', '.join(keyvalue))
   if(choice == '6'):  #quit our program
       sys.exit()
   print()
   print()

[/i]The over-sized and bolded code is where I am stuck. Each time I run the script I get back :

yahoo

0['yahoo', 'XqffoZeo']
1['google', 'CoIushujSetu']


Help? Please?
Reply
#2
cylandur your post is a mess i've tried reformatting it various times to no avail, could you please create a new thread for your problem and use the correct python code tags to post your code.

These posts will be deleted once this is done.

Thanks
Reply
#3
(Oct-11-2016, 12:16 AM)Yoriz Wrote: cylandur your post is a mess i've tried reformatting it various times to no avail, could you please create a new thread for your problem and use the correct python code tags to post your code.
I could fix code tag in the post,but we leave as info for now about why this is happening.
When copy code for web it can sometime preserve HTML code,
and then MyBB will convert that code into MyCode(BBCode).

The simple solution is first copy into a text editor,simple as eg Notepad or Gedit.
Then when copy from editor to thread it will be okay(now can right code tag by applied in Post editor(Sceditor)).
Reply
#4
Also people seem confused on how to start there post outside of a quote, continuing there post inside of a quoted post.
Reply
#5
Quote:Also people seem confused on how to start there post outside of a quote, continuing there post inside of a quoted post.
Ive noticed this too. Im not sure why though. But it been more than one person. But its the same BBCode as before.

Wow, i just realized that cylandur was quoting the other post...not making a new post because of that too.
Recommended Tutorials:
Reply
#6
Quote:The simple solution is first copy into a text editor,simple as eg Notepad or Gedit.

This is what I have been doing.
Reply
#7
You know there is a remove formatting option in the BBcode buttons that does the same thing, right?
Recommended Tutorials:
Reply
#8
I do now!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] University Assignment Help needed Nomathemba 3 3,473 Nov-10-2023, 05:50 AM
Last Post: ezrahidaya
  [split] new to python hello world code gives errors giobastidas1970 1 1,446 Mar-11-2023, 12:48 PM
Last Post: jefsummers
  [split] assignment help Shobana 2 1,300 Nov-11-2022, 12:10 PM
Last Post: Larz60+
  [split] Python for Everybody 5.2 assignment ramadan2099 3 12,033 Jul-15-2020, 04:54 PM
Last Post: Bipasha
  [split] help me make this code better please (basic) Rustam 2 2,248 Jun-19-2020, 01:27 PM
Last Post: Rustam
  [split] Python for Everybody 5.2 assignment jonchanzw 4 8,448 Oct-22-2019, 08:08 AM
Last Post: perfringo
  morse code assignment raymond2688 11 8,524 Jul-29-2019, 07:43 PM
Last Post: raymond2688
  Write pseudo code for a class assignment Scrimshot 3 3,369 May-07-2019, 05:38 PM
Last Post: Scrimshot
  Need some help with a bit of code for an assignment. JackMercer50 1 2,269 Feb-09-2019, 04:13 PM
Last Post: stullis
  Need help with lists to continue my assignment code tinabina22 9 10,353 Oct-12-2016, 12:20 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020