I seem to be creating lists within lists in this code. The .join at the end does work and removes the brackets, yet there are still more in the output. How do I fix this?
#method for encrypting message
def encptMessage(keycol, msg):
#adds the extra brackets and quotations
#but don't know how to remove without
#program failing
ciphertxt = [''] *keycol
#checkpoint 1
print(ciphertxt)
for column in range(keycol):
pointer = column
#increases row
while pointer < len(msg):
ciphertxt[column] += msg[pointer]
#checkpoint 2
print(ciphertxt)
pointer += keycol
return ''.join(ciphertxt)
#############################################################################
#runs if user wants to encrypt
if (edchoice == "-e"):
#applies key length and file text
#to method
ciphertxt = encptMessage(key, mytext)
#outputs ciphertext
#checkpoint 3
print(ciphertxt + '|')
print("Encryption is done")
#sends ciphertext to a new file
#or updates previous file
fixedctxt = ciphertxt.replace('[','').replace(']','').replace("'",'')
with open('encrypt.txt', 'w') as f:
f.write(fixedctxt)
- checkpoint 1: ['', '', '', '', '', '']
- checkpoint 2: first loop: ['[', '', '', '', '', '']
- checkpoint 2: 20th loop: ['[aaaa', "'aaaa", "aaaa'", 'aaaa]', '', '']
- checkpoint 3: [ietg'ssmehiee'iscs]ttrshhea|
- input: hithisisthesecretmessage
- intended output: Ttrshheaietgssmeieescs|