Understanding an encryption technique algorithm I have trouble understanding steps for Key set generation mentioned in an article titled as "An optimized encryption technique using an arbitrary matrix with probabilistic encryption". The steps are:


Consider the sequence for 0 to n-1 values for a source text of size n = pow (p, p) characters. 
Convert each element of the sequence into a form with base p. 
Represent the values of step 2 in a matrix form A of order n x p. 
Subtract 1 from each element of A. 
Consider a random matrix B of size p x p. 
Multiply the matrix A with B to generate a result matrix R. 
Substitute all positive integers of R with +1, negative integers to -1 and zero by 0 using a substitute function. 
Increment each element of R by 1. 
Convert each row of R, from the base p to decimal to generate the key sequence set. 


I can't understand how this works. Can you explain these steps with an example? Or pseudocode?
To be honest, this paper looks like garbage. It refers to Base64 as an "encryption algorithm" in section 2.2. Figures 1 and 2 were 
created by a moron. But anyway...



  Consider the sequence for 0 to n-1 values for a source text of size n = pow (p, p) characters.


If $p = 4$, then $n = p^p = 256$ and we'll be working with a block of 256 bytes. But for brevity, I'll consider the simpler case where $p = 3$ and restrict the cipher alphabet to the 26 letters of the alphabet plus the space character.

Presumably the pass phrase will have to be padded to the block size before applying this algorithm, but the paper doesn't describe how to do this. Let's assume we're starting with the 27-character keyphrase THIS IS MY SECRET KEYPHRASE.

  Convert each element of the sequence into a form with base p.


If ' '=000, 'A'=001, 'B'=002 and so on, up to 'Z'=222, we get the following:

202 022 100 201 000 100 201 000 111 221 000 201 012 010 200 012 202 000
102 012 221 121 022 200 001 201 012


  Represent the values of step 2 in a matrix form A of order n x p.


$$A = \begin{bmatrix}
2&amp;0&amp;2&amp;0&amp;2&amp; \dots &amp;0&amp;0&amp;1&amp;1&amp;1\\
2&amp;2&amp;1&amp;0&amp;0&amp; \dots &amp;0&amp;2&amp;0&amp;0&amp;0\\
1&amp;0&amp;2&amp;0&amp;1&amp; \dots &amp;0&amp;1&amp;0&amp;1&amp;2\\\end{bmatrix}$$

  Subtract 1 from each element of A.


$$A = \begin{bmatrix}
1&amp;-1&amp;1&amp;-1&amp;1&amp; \dots &amp;-1&amp;-1&amp;0&amp;0&amp;0\\
1&amp;1&amp;0&amp;-1&amp;-1&amp; \dots &amp;-1&amp;1&amp;-1&amp;-1&amp;-1\\
0&amp;-1&amp;1&amp;-1&amp;0&amp; \dots &amp;-1&amp;0&amp;-1&amp;0&amp;1\\\end{bmatrix}$$

  Consider a random matrix B of size p x p.


This is under-specified. But let's assume the elements of $B$ are all in the range from $0$ to $n-1$:

$$B = \begin{bmatrix}
21&amp;16&amp;5\\
15&amp;23&amp;8\\
3&amp;10&amp;10\\\end{bmatrix}$$

  Multiply the matrix A with B to generate a result matrix R.


$$R = B \times A = \begin{bmatrix}
37&amp;-10&amp;26&amp;-42&amp;5&amp;\dots&amp;-42&amp;-5&amp;-21&amp;-16&amp;-11\\
38&amp;0&amp;23&amp;-46&amp;-8&amp;\dots&amp;-46&amp;8&amp;-31&amp;-23&amp;-15\\
13&amp;-3&amp;13&amp;-23&amp;-7&amp;\dots&amp;-23&amp;7&amp;-20&amp;-10&amp;0\\\end{bmatrix}$$

  Substitute all positive integers of R with +1, negative integers to -1 and zero by 0 using a substitute function.


$$R = \begin{bmatrix}
1&amp;-1&amp;1&amp;-1&amp;1&amp;\dots&amp;-1&amp;-1&amp;-1&amp;-1&amp;-1\\
1&amp;0&amp;1&amp;-1&amp;-1&amp;\dots&amp;-1&amp;1&amp;-1&amp;-1&amp;-1\\
1&amp;-1&amp;1&amp;-1&amp;-1&amp;\dots&amp;-1&amp;1&amp;-1&amp;-1&amp;0\\\end{bmatrix}$$

Wait a minute; if $p &gt; 3$, then isn't matrix $R$ going to consist mostly of ones? Maybe $B$ should also include negative values? Who knows?

  Increment each element of R by 1.


$$R = \begin{bmatrix}
2&amp;0&amp;2&amp;0&amp;2&amp;\dots&amp;0&amp;0&amp;0&amp;0&amp;0\\
2&amp;1&amp;2&amp;0&amp;0&amp;\dots&amp;0&amp;2&amp;0&amp;0&amp;0\\
2&amp;0&amp;2&amp;0&amp;0&amp;\dots&amp;0&amp;2&amp;0&amp;0&amp;1\\\end{bmatrix}$$

  Convert each row of R, from the base p to decimal to generate the key sequence set.


This can't be right. Although $p=3$ in this example, the elements of $R$ consist of the values 0, 1 and 2 for any value of $p$. However, according to the encryption algorithm discussed later in the paper, we're supposed to end up with a set of $n$ values. So I guess we just replace each group of $p$ elements in $R$ with the result of interpreting them as digits in base $p$:

$$K = \begin{bmatrix}
20&amp;8&amp;18&amp;20&amp;0&amp;18&amp;11&amp;9&amp;0\\
23&amp;1&amp;18&amp;2&amp;0&amp;18&amp;2&amp;20&amp;0\\
20&amp;2&amp;18&amp;8&amp;6&amp;18&amp;2&amp;20&amp;1\\\end{bmatrix}$$

When flattened into a string of characters from the cipher alphabet, this is the result:

THRT RKI WARB RBT TBRHFRBTA





I'll probably lose the will to live if I start wading through the encryption algorithm, so I'll stop here.