I needed the result as a char array of the secret key combined with alphabets in 5x5:
import numpy as np
def playfair():
key=input("Enter the secret key")
key+='abcdefghiklmnopqrstuvwxyz'
size=len(key)
for i in range(size):
if key[i]=='j':
key[i]='i'
for j in range(i+1,size):
if key[j]==key[i]:
for k in range(j,size):
key[k]=key[k+1]
size-=1
else: j+=1
play = np.zeros((5, 5), 'U1')
play.flat[:32] = list(key)
playfair()
play
But i got this error instead on entering the secret key , in this case the key i entered is "secret"
Enter the secret key
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-49-e0a72d62bfc0> in <module>
18 play = np.zeros((5, 5), 'U1')
19 play.flat[:32] = list(key)
---> 20 playfair()
21 play
22
<ipython-input-49-e0a72d62bfc0> in playfair()
11 if key[j]==key[i]:
12 for k in range(j,size):
---> 13 key[k]=key[k+1]
14 size-=1
15 else: j+=1
TypeError: 'str' object does not support item assignment