Algebra plays a bigger role in computing than expected. A few beginner rogrammers may notice that variables can be manipulated similarly to variables in algebra. For instance, adding five to a number which is defined by a function. What I am focusing on is the idea of a matrix and how that can be used in programming.
In pure maths, a matrix is a collection of vectors. However it can be used in other ways. It may be used as a 'table' of values. Let's assume we want to represent profit per quarter over four years. We could let each row equal the quarter and column equal year so that we form a 4 by 4 square matrix. This is exactly the same as creating a multidimensional array. This can be proven by the fact that this sort of array can be represented geometrically in two dimensions. This is similar to a matrix.
But that is just one use. We could use it in encryption.
Suppose we want to encrypt the password "password" to be stored in a database.
If we allow each letter of the alphabet to be equal to a number corresponding to its position such that
a=1 b=2 c=3 ...
Then our password can be rewritten as
16 1 19 19 23 15 18 4
We can split this into three groups of three numbers each (if less than three number are in a group then the value of the missing number(s) is zero.) We should end up with nine numbers in three groups. By allowing the first number of each group to be in row one - ordered by group umber - and continuing in this fashion we get the matrix
16 19 18
1 23 4
19 15 0
The next step is to multiply by an encoding matrix. Because this has an infinite amount of values, it is hard to undo this encryption from a hacking perspective. We'll let this matrix equal
-3 -3 -4
0 1 1
-4 3 4
So that the product is
-120 25 27
-19 32 35
-57 -42 -61
If we reverse the process for converting the text into a matrix, our encrypted password is
-120 -19 -56 25 32 -42 27 35 -61
A hacker seeing this would have a hard time seeing what these numbers mean. Even if he realised it came from a matrix multiplication he'd have to work out the encoding matrix. Plus we could make a more sophisticated method for assigning numbers to letters making our encryption more dense. We could also make the encoding matrix dependant on what was inputted so it is harder to guess it.
The major advantage of this is that it's easy to decode with the inverse of the encoding matrix since this multiplied by the product to return to our original matrix.
I will post other uses of maths in future blogs butt for now, adios.
…I think I understand. Basically, once it's an encoded matrix, you just need to de-matrixify it, divide it by the encoding number, and just substitute the numbers for letters, right?
LinkZelda
27 Aug 2013 14:44
In reply to charizardman283
You need to multiply the encoded matrix by the inverse of the encoding matrix to return to the original. Here is the proof.
The identity matrix I is one which is identical to 1 such that a matrix M multiplied by I equals the original matrix, that is
MI=M
An inverse matrix M-1 multiplied by the corresponding matrix results in the identity matrix.
MM-1 = I
In this example we have the password matrix P and the encoding matrix E. Multiplying these results in
PE = Em
Where Em is the encrypted password.
The inverse of E (E-1) can then be multipled into both sides to give
PEE-1=EmE-1
Recall that MM-1=I
Our equation then becomes
PI=EmE-1
Therefore the password matrix equals the resultant matrix multiplied by the inverse matrix (since PI = P).
I'm a little curious now.
How does M-1 equal the inverse?
LinkZelda
27 Aug 2013 17:20
In reply to charizardman283
The -1 should be in superscript. This is a hypothetical matrix that will transform it's counter part into the identity matrix. For some matrices this doesn't exist. In my proof we assume the encoding matrix does have one. It is extremely difficult to compute it by hand so I didn't define the matrix M.
Matrices are used heavily in analytic geometry and linear algebra for transformations of coordinates. A 4x4 matrix represents rotation, translation, and identity. By multiplying a coordinate matrix by this, any 3D graphical representation can be repositioned anywhere in 3D space. Most modern graphical hardware has built-in magic transformations, including the DS, 3DS, iOS platforms (especially noticeable with all the 3D flips windows do), computers (video cards and CPUs), and game consoles.
LinkZelda
27 Aug 2013 14:48
In reply to HullBreach
All that advanced algebra just to make Super Mario games!
In web development I have never used matrices but when I was making a program for my TI calculator then I had no choose but to use them. In a way a matrix is like an array but not really.
LinkZelda
27 Aug 2013 06:52
In reply to lilwayne1556
It only works exactly like an array if it's pure numbers. If it's an array with words you can convert it into binary and store it that way. A matrix is the most convienient method for a computer and human since it
can easily be done with a set of instructions and interpreted by humans.