|
Viewing Single Post From: Affine Hill Cipher via Homogeneous coordinates
|
|
jdege
|
Jun 20 2009, 07:47 PM
|
- Posts:
- 263
- Group:
- Admin
- Member
- #246
- Joined:
- December 7, 2006
|
OK, I tried this out, and it works.
I built a little command-line calculator that does matrix math, mod-26, and then used it in some scripts to try Affine Hill Cipher encoding and decoding, both in the normal manner and by using homogeneous coordinates.
Start, our plaintext: "HELLO". Converted to vectors of two ints mod-26, this is [7 4] [11 11] [14 0].
For encrypting, we'll use the key matrix - Code:
-
[[3[space]7] [12[space]3]] and the key vector - Code:
-
[21[space]14] . Encryption is multiplying each vector by the key matrix and then adding the key vector: - Code:
-
[[space]7[space]4[space]][space]*[space][[3[space]7][space][12[space]3]][space]+[space][21[space]14][space]=[space][12[space]23] [[space]11[space]11[space]][space]*[space][[3[space]7][space][12[space]3]][space]+[space][21[space]14][space]=[space][4[space]20] [[space]14[space]0[space]][space]*[space][[3[space]7][space][12[space]3]][space]+[space][21[space]14][space]=[space][11[space]8]
[12 23] [4 20] [11 8] converts to the letters "MXEULI".
To decrypt, we need to invert the key matrix, and negate the key vector. This gives us - Code:
-
[[1[space]15] [22[space]1]] and - Code:
-
[5[space]12] .
We need to subtract the negated key vector and then multiply by the inverted key matrix:- Code:
-
([space][[space]12[space]23[space]][space]+[space][5[space]12][space])[space]*[space][[1[space]15][space][22[space]1]][space]=[space][7[space]4][space] ([space][[space]4[space]20[space]][space]+[space][5[space]12][space])[space]*[space][[1[space]15][space][22[space]1]][space]=[space][11[space]11] ([space][[space]11[space]8[space]][space]+[space][5[space]12][space])[space]*[space][[1[space]15][space][22[space]1]][space]=[space][14[space]0]
Which gives us "HELLOA" - our original string plus the padding we added to make up the final vector.
OK. Now let's do it with homogeneous coordinates.
Our conversion to integers is the same, but we now make up three vectors of size three, using 1 as the last coordinate of each vector. Our plaintext vectors, then, are - Code:
-
[7[space]4[space]1][space][space][11[space]11[space]1][space][space][14[space]0[space]1] .
Our multiplication matrix is now - Code:
-
[[3[space]7[space]0] [12[space]3[space]0] [0[space]0[space]1]], . Our addition step is now another matrix: - Code:
-
[[1[space]0[space]0] [0[space]1[space]0] [21[space]14[space]1]] . Because these are matrices, we can multiply them together:- Code:
-
[[3[space]7[space]0][12[space]3[space]0][0[space]0[space]1]][space]*[space][[1[space]0[space]0][0[space]1[space]0][21[space]14[space]1]][space]=[space][[3[space]7[space]0][12[space]3[space]0][21[space]14[space]1][space]] . The encrypting math, then, is:- Code:
-
[[space]7[space]4[space]1][space]*[space][[3[space]7[space]0][space][12[space]3[space]0][21[space]14[space]1]][space]=[space][12[space]23[space]1] [[space]11[space]11[space]1][space]*[space][[3[space]7[space]0][space][12[space]3[space]0][21[space]14[space]1]][space]=[space][4[space]20[space]1] [[space]14[space]0[space]1][space]*[space][[3[space]7[space]0][space][12[space]3[space]0][21[space]14[space]1]][space]=[space][11[space]8[space]1] .
In no great surprise, this gives us the same results as the first method.
To decrypt in homogeneous coordinates, we need to first, subtract by the additive matrix, and then multiply by the inverse of the multiplicative matrix.
The negation of - Code:
-
[[1[space]0[space]0] [0[space]1[space]0] [21[space]14[space]1]] is - Code:
-
[[space][25[space]0[space]0] [0[space]25[space]0] [5[space]12[space]25][space]] . The inverse of - Code:
-
[[space][1[space]15[space]0] [22[space]1[space]0] [space][0[space]0[space]1]] . These follow directly from the keys we used in the two-dimensional case. Again, we can combine them by multiplying - in the opposite order than we did in encrypting. Remember, matrix math is not commutative, and the inverse of the product of two matrices is the product of the inverses in reverse order.
So, - Code:
-
[[25[space]0[space]0][0[space]25[space]0][5[space]12[space]25]][space]*[space][[1[space]15[space]0][22[space]1[space]0][0[space]0[space]1]][space]=[[25[space]11[space]0][4[space]25[space]0][9[space]9[space]25][space]] .
And our decryption step is:- Code:
-
[12[space]23[space]1][space]*[space][[1[space]15[space]0][space][22[space]1[space]0][space][9[space]9[space]1]][space]=[space][7[space]4[space]1] [4[space]20[space]1][space]*[space][[1[space]15[space]0][space][22[space]1[space]0][space][9[space]9[space]1]][space]=[space][11[space]11[space]1] [11[space]8[space]1][space]*[space][[1[space]15[space]0][space][22[space]1[space]0][space][9[space]9[space]1]][space]=[space][14[space]0[space]1]
Which is, again, exactly what we got before.
All-in-all, the whole exercise was pretty much a waste of time, except that now and again it's fun to dig in and confirm what you thought you understood of what other people have been teaching you.
|
|
When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.
|