# Create a matrix message1 message1<-matrix(c("A","T","T","A","C","K"," ","T","H","E"," ", "C","A","S","T","L","E"," ","A","T"," ", "D","A","W","N"),nrow=5,byrow=T) # Display m message1 # Generate the ciphertext ciphertext1<-c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) for(i in 1:5) { ciphertext1[i]<-message1[6-i,5] } for(i in 6:10) { ciphertext1[i]<-message1[i-5,4] } for(i in 11:15) { ciphertext1[i]<-message1[16-i,3] } for(i in 16:20) { ciphertext1[i]<-message1[i-15,2] } for(i in 21:25) { ciphertext1[i]<-message1[26-i,1] } # Display ciphertext1 ciphertext1 # Generate an appropriate matrix message2 message2<-matrix(c("A","T","T","A","C","K"," ","T","H","E"," ", "C","A","S","T","L","E"," ","A","T"," ", "D","A","W","N"," "," "),nrow=3,byrow=T) message2 #generate ciphertext2 ------ read by columns ciphertext2<-c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) for(i in 1:9) #columns indice { for(j in 1:3) #row indice { ciphertext2[3*(i-1)+j]=message2[j,i] } } # display ciphertext2 ciphertext2 #generate ciphertext3 ------ read it diagonally up and down from the bottom right corner ciphertext3<-c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) k<-1 # k is the indice of vector ciphertext3 m<-3 n<-9 # start from (3,9) for(i in 1:11) #loop for 3+9-1 times, 第i条对角线上元素坐标和等于13-i { if(i%%2==0) #对角线执行序号为偶数,向下走。 奇数向上走 { while(m<=3&n>=1) #把这条线走完 { ciphertext3[k]<-message2[m,n] #m=3,n=6时, k<-k+1 m<-m+1 n<-n-1 } if(m>3) { m=3 n=12-i-m } if(m==3&n==0) { m<-1 n=1 } } else { while(m>=1&n<=9) { ciphertext3[k]<-message2[m,n] k<-k+1 m<-m-1 n<-n+1 #m=1,n=9时,加减完m=0,n=10, 本应该m=1,n=8 } if(n>9&m==2) #向上走的边界 { m<-2 n<-9 } if(n>9&m==0) { m<-1 n<-8 } if(n<9&m<1) { m<-1 n<-12-i } } } message2 ciphertext3 #Which of the two matrices, message1 or message2 do you think produces the most secure encryption methods? # In my opinion, message2 produces the most secure encryption methods # because message2 is 3*9 matrix,we get more elements to make up the password