Hello..
I am working on this project which is to use a matrix to encrypt a string& a text file and to decrypt them as well.
The matrix that I need to use is this one, but I still don't know how to make it shift each character to the right by one position each time it creates a new row.
public class Matrix
{
private final int SIZE = 45;
private char[ ] [ ] matrix;
private String alpha;
public Matrix()
{
alpha = createString();
matrix = new char[SIZE][SIZE];
fillMatrix();
}//end const
private String createString()
{
StringBuilder sb = new StringBuilder();
//make the string
for(char c = 'A'; c <= 'Z'; c++)
sb.append(c);
sb.append(" .!;:,$%#@=&*()+=<>");
return sb.toString();
}//end create
private void fillMatrix()//fill matrix according to plan
{
for(int row = 0; row < SIZE; row++)
{
for(int col = 0; col < SIZE; col++)
{
matrix[row][col]= alpha.charAt(col);
System.out.print(matrix[row][col]);
}//end for
//shift
//add chars for front of alpha to back of matrix row
System.out.println();
}//end for
}//end build
public String toString()
{
return "toString answer goes back: ";
}//end twoString
public static void main(String[ ] args)
{
Matrix m = new Matrix();
System.out.println(m.createString());
//System.out.println();
}//end main
}//end class
It should look like this:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
BCDEFGHIJKLMNOPQRSTUVWXYZ A
CDEFGHIJKLMNOPQRSTUVWXYZ AB
DEFGHIJKLMNOPQRSTUVWXYZ ABC
EFGHIJKLMNOPQRSTUVWXYZ ABCD
FGHIJKLMNOPQRSTUVWXYZ ABCDE
GHIJKLMNOPQRSTUVWXYZ ABCDEF
HIJKLMNOPQRSTUVWXYZ ABCDEFG
IJKLMNOPQRSTUVWXYZ ABCDEFGH
JKLMNOPQRSTUVWXYZ ABCDEFGHI
KLMNOPQRSTUVWXYZ ABCDEFGHIJ
LMNOPQRSTUVWXYZ ABCDEFGHIJK
MNOPQRSTUVWXYZ ABCDEFGHIJKL
NOPQRSTUVWXYZ ABCDEFGHIJKLM
OPQRSTUVWXYZ ABCDEFGHIJKLMN
PQRSTUVWXYZ ABCDEFGHIJKLMNO
QRSTUVWXYZ ABCDEFGHIJKLMNOP
RSTUVWXYZ ABCDEFGHIJKLMNOPQ
STUVWXYZ ABCDEFGHIJKLMNOPQR
TUVWXYZ ABCDEFGHIJKLMNOPQRS
UVWXYZ ABCDEFGHIJKLMNOPQRST
VWXYZ ABCDEFGHIJKLMNOPQRSTU
WXYZ ABCDEFGHIJKLMNOPQRSTUV
XYZ ABCDEFGHIJKLMNOPQRSTUVW
YZ ABCDEFGHIJKLMNOPQRSTUVWX
Z ABCDEFGHIJKLMNOPQRSTUVWXY
ABCDEFGHIJKLMNOPQRSTUVWXYZ
except it should include characters too.