[Tutor] I am trying to get my encryption program to print from my def main. I am just learning the program.

Corneil Lionel cjl14a at acu.edu
Fri May 1 12:48:24 CEST 2015


text_list=[]
temp=[]
import allison
import corneil
def main():
    choice=input("Would you like to begin? y/n: ")
    while choice!='n':
        d=cipher()

alphabet=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
        print('Would you like to encrypt or decrypt your text?')
        choice=input('Enter "e" to encrypt or "d" to decrypt: ')
        while choice!="d" and choice!="e":
            print("That is not a valid option, please choose again.")
            choice=input('Enter "e" to encrypt or "d" to decrypt: ')
        if choice=="e":
            text=intro("plain")
            corneil.encrypt(text,d,alphabet)
        else:
            text=intro("encrypted")
            #print(text)
            allison.decrypt(text,d,alphabet)
        print()
        choice=input("Would you like to go again? y/n: ")


def cipher():
    d={}
    temp=[]
    try:
        f=open('cipher.txt','r')
        for x in f:
            temp=x.rstrip().split(':')
            d[temp[0]]=temp[1]
    except Exception as err:
        print(err)
    return d

def intro(x):
    print('Please enter your',x,'text. Type "quit" to quit.')
    text=input("")
    y=""
    while text!="quit":
        y+=text.upper()
        #text_list.append(text)
        text=input()
    return y

main()
AND THIS IS NOT PRINTING OUT WHEN I TRY TO ENCODE

def encrypt(text,cipher,a):
     encrypted=""
     for char in text:
          if char in cipher:
               encrypted+=cipher[char.upper()]#or lower depending on what
is in cypher.txt
          else:
               encrypted+=char

     return encrypted
     print(encrypted)


More information about the Tutor mailing list