#create code lock
Polybius<-matrix(c(NA,'V',NA,'L','Z',NA,'J',NA,
                   'M','A','I',NA,'D',NA,'S','C',NA,
                   'R','B',NA,'K',NA,'P','U','W','E',
                   'Y','H','Q',NA,NA,'N',NA,'T','F',
                   NA,'G','O',NA,
                   'X'),nrow = 4,ncol = 10)
#change index
colnames(Polybius)<-c(0:9)
rownames(Polybius)<-c(0:3)

#obtain parameters
Ciphertext<-c(2,4,1,6,0,6,3,6,1,6,1,4,1,6,2,6,1,9,3,5,1,4,1,6,3,7,1,6,0,2,2,6,2,2,2,3,3,7,1,9,1,8,0,0,8)
plaintext<-NULL
length<-length(Ciphertext)%/%2

#add word into plaintext if the index exist in code lock and the word is not NA
for(i in 1:length){
  if(Ciphertext[2*i-1]>-1&Ciphertext[2*i-1]<4){
    if(is.na(Polybius[(Ciphertext[1+(i-1)*2]+1),(Ciphertext[2+(i-1)*2]+1)])==FALSE){
      plaintext<-c(plaintext,Polybius[(Ciphertext[1+(i-1)*2]+1),(Ciphertext[2+(i-1)*2]+1)])
    }
  }
}

#reshape
plaintext<-paste(plaintext,collapse='')

##Answer one : show plaintext
plaintext


print("Task2 answer1 plaintext is ")
print(plaintext)
