### Affine and Hill ciphers documentation

parent 22a1838f
Pipeline #32822934 passed with stages
in 1 minute and 13 seconds
 ... ... @@ -27,6 +27,7 @@ Given a version number MAJOR.MINOR.PATCH - Project released under the MIT license - MPI Toom-Cook-3 multiplier - Hill classical cipher - Polyalphabetic affine cipher [0.0.6] - 2017-07-09 -------------------- ... ...
 ... ... @@ -104,6 +104,7 @@ Classical ciphers ### Substitution ciphers - Hill cipher - Polyalphabetic Affine cipher Utilities ... ...
 /* * The following algorithm is not secure and is provided as an * historical reference only. * The following cipher mix together the affine and the substitution * ciphers. * * Affine cipher encryption function: * E(x) = (ax + b) * D(y) = (y - b)*a^-1 * To allow a correct decryption is fundamental that gcd(a,256)=1 * and that is the case for all the odd numbers less than 256. * The original affine cipher is a monoalphaberic substitution cipher where * each octet is encrypted using a simple linear function performed modulo * 256. * * To exploit the properties of the vigenere cipher we make a list of * numbers 'a's and 'b's to be used as keys for the affine cipher. * Encryption function: E(x) = (ax + b) = y * Decryption function: D(y) = (y - b)*a^-1 = x * * Note that to be invertible the value 'a' should be chosen so that * gcd(a,256)=1 and, since 256=2^8, this is true whenever the value * of 'a' is odd. * * The provided implementation allows the usage of a list of 'a' values * and 'b' values, thus it can be more appropriately classified as a * polyalphabetic affine cipher. * * Given the two variable length 'keys' the implementation provides the * following well known ciphers: * - Caesar : keylen = 1, keya = {1}, keyb = {3} * - Rot-X : keylen = 1, keya = {1}, keyb = {X} * - Affine : keylen = 1, keya = {a}, keyb = {0} * - Vigenere : keylen > 1, keya = {1,...,1}, keyb = {b1,...,bn} * - Poly-Affine: keylen > 1, keya = {a1,...,an}, keyb = {b1,...,bn} */ #ifndef CRY_AFFINE_H_ ... ...
 /* * The following algorithm is not secure and is provided as an * historical reference only. * * The Hill cipher is a polygraphic substitution cipher based on linear * algebra. * * Given a nxn matrix A that is invertible modulo 256. To encrypt a message * each cleartext block of n octets is treated as an n elements vector * and left multiplied by A. * To decrypt the message each ciphertext block of n octets is instead left * multiplied by the inverse matrix A^-1. * * Given the cleartext x= and the ciphertext y= * Encryption function: E(x) = A * x = y * Encryption function: D(y) = A^-1 * y = x * * To be invertible modulo 256, the matrix determinant det should be * a unit (invertible) modulo 256. Thus there should be a value idet such * that det*idet = 1 (mod 256). * From theory We know that idet exists iff gcd(det,256)= 1 and, since * 256=2^8, this is true whenever the determinant value is odd. */ #ifndef CRY_HILL_H_ #define CRY_HILL_H_ ... ... @@ -8,6 +32,7 @@ #define CRY_HILL_KEYGEN_TRIALS 100 struct cry_hill_ctx { unsigned char key[CRY_HILL_KEYLEN_MAX]; unsigned char ikey[CRY_HILL_KEYLEN_MAX]; ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!