(10%) Determine whether the following code has syntax erros or
not. If it is correct, predict its output. If it is
incorrect, point out the mistake(s).
# String Methods (P.142)
def main():
plaintext = "XHOSCTISEMNHLI"
t = ['ABCDE', 'FGHIJ', 'KLMNO', 'PQRST', 'UVWXY']
ciphertext = enc(plaintext, t)
print(ciphertext)
def enc(s, tabula):
ciphertext = ""
for i in range(0, len(s)-1, 2):
x1, y1, x2, y2 = findDiagonal(tabula, s[i:i+2])
c3c4 = getDiagonal(tabula, x1, y2, x2, y1)
ciphertext = ciphertext + c3c4
return ciphertext
def getDiagonal(tabula, x1, y1, x2, y2):
return tabula[x1][y1] + tabula[x2][y2]
def findDiagonal(tabula, s):
# s is a 2-character string
c1, c2 = s[0], s[1]
longStr = "".join(tabula)
p1 = longStr.find(c1)
x1, y1 = p1 // 5, p1 % 5
p2 = longStr.find(c2)
x2, y2 = p2 // 5, p2 % 5
return x1, y1, x2, y2
main()