I am new to python and am stuck on the task below. Below is an example of my input file and what I want it to output.
Input File Message (from online sample)
So pure of heart
And strong of mind
So true of aim with his marshmallow laser
Marshmallow laser
Output File Message
LhtinkXthYtaXTkm
ugWtlmkhgZthYtfbgW
LhtmknXthYtTbftpbmatabltfTklafTeehpteTlXk
FTklafTeehpteTlXk
Below is my syntax and guidance as to why it isn't completing the task intended would be helpful. It is printing 'wwww'....I believe it is a 'w' for each line.
inputFileName = input("Enter the message to encrypt: ")
key = int( input("Enter the shift key: " ))
outputFileName = input("Enter the output file name: " )
infile=open(inputFileName,"r")
outfile = open( outputFileName, "w" )
sequence=infile.readlines()
alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
shiftedAlphabetStart = alphabet[len(alphabet) - key:]
shiftedAlphabetEnd = alphabet[:len(alphabet) - key]
shiftedAlphabet = shiftedAlphabetStart + shiftedAlphabetEnd
print( alphabet )
print( shiftedAlphabet )
encryptedMessage = ''
for character in sequence:
letterIndex = alphabet.find( character )
encryptedCharacter = shiftedAlphabet[letterIndex]
#print( "{0} -> {1}".format( character, encryptedCharacter ) )
encryptedMessage = encryptedMessage + encryptedCharacter
print( "The encrypted message is: {0}".format( encryptedMessage ))
string.ascii_lettersinstead of writing the whole alphabet