Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assignment
#7
I need for this code

for i in range(len("samplepasswordfile")):
   i = [0,1]

to find these passwords

passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]

it goes as far as #2, ask me what password I want to look up
yahoo
google

I type in google or yahoo, and it starts all over at #1

within this code

import csv
import sys

#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()

       for i in range(len("samplepasswordfile")):
           i = [0,1]
Reply


Messages In This Thread
Assignment - by tinabina22 - Oct-06-2016, 12:58 AM
RE: Assignment - by Larz60+ - Oct-06-2016, 03:03 AM
RE: Assignment - by Skaperen - Oct-06-2016, 04:36 AM
RE: Assignment - by sparkz_alot - Oct-06-2016, 01:35 PM
RE: Assignment - by tinabina22 - Oct-06-2016, 09:54 PM
RE: Assignment - by nilamo - Oct-06-2016, 09:59 PM
RE: Assignment - by tinabina22 - Oct-06-2016, 11:10 PM
RE: Assignment - by Yoriz - Oct-06-2016, 11:35 PM
RE: Assignment - by tinabina22 - Oct-06-2016, 11:36 PM

Forum Jump:

User Panel Messages

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