I have pin-pointed where I think the error is. Parts of the program are also explained through the comments I have written below.
The logical error is that the entire encrypted message is a single letter, which is the first letter (i.e. string[0]
) of the plaintext that the user enters. There must be a problem with the for
loop that inserts the plaintext into the row arrays not iterating through the plaintext string correctly.
row1 = [' ', ' ', ' ', ' ', ' ', ' '] #initialise the rows as arrays
row2 = [' ', ' ', ' ', ' ', ' ', ' ']
row3 = [' ', ' ', ' ', ' ', ' ', ' ']
row4 = [' ', ' ', ' ', ' ', ' ', ' ']
row5 = [' ', ' ', ' ', ' ', ' ', ' ']
row6 = [' ', ' ', ' ', ' ', ' ', ' ']
def updateRow(aList, text, index): #function for removing spaces and inserting plaintext letters
indexOfText = text[index]
for i in range(1,7): #logic error in this loop
aList.remove(' ')
aList.insert(i, indexOfText)
return aList
def createColumn(row1, row2, row3, row4, row5, row6, index): #function for creating columns by adding the rows with the same index
column = row1[index] + row2[index] + row3[index] + row4[index] + row5[index] + row6[index]
return column
def encrypt(col1, col2, col3, col4, col5, col6): #function for adding the columns together to produce the enciphered message
cipher = col1 + col2 + col3 + col4 + col5 + col6
return cipher
while True:
plaintext = input("Enter you message:") #input plaintext
row1Pop = updateRow(row1, plaintext, 0) #populate rows with plaintext
... #continues
row6Pop = updateRow(row6, plaintext, 0)
column1 = createColumn(row1Pop, row2Pop, row3Pop, row4Pop, row5Pop, row6Pop, 0) #create required columns
... #continues
column6 = createColumn(row1Pop, row2Pop, row3Pop, row4Pop, row5Pop, row6Pop, 5)
ciphertext = encrypt(column1, column2, column3, column4, column5, column6) #create final encrypted message
print(ciphertext) #display encrypted message
break
An example input would be:
this is my first attempt at it today
And the output for this becomes:
tttttttttttttttttttttttttttttttttttt
The output is meant to be this (if the program was working correctly):
tsit h rtatimsetosytm d piaifatty