Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
cry
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
12
Issues
12
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
crylib
cry
Commits
7d2311b1
Commit
7d2311b1
authored
Oct 12, 2018
by
Davide Galassi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Affine and Hill ciphers documentation
parent
22a1838f
Pipeline
#32822934
passed with stages
in 1 minute and 13 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Sidebyside
Showing
4 changed files
with
48 additions
and
9 deletions
+48
9
CHANGELOG.md
CHANGELOG.md
+1
0
README.md
README.md
+1
0
include/cry/affine.h
include/cry/affine.h
+21
9
include/cry/hill.h
include/cry/hill.h
+25
0
No files found.
CHANGELOG.md
View file @
7d2311b1
...
...
@@ 27,6 +27,7 @@ Given a version number MAJOR.MINOR.PATCH

Project released under the MIT license

MPI ToomCook3 multiplier

Hill classical cipher

Polyalphabetic affine cipher
[0.0.6]  20170709

...
...
README.md
View file @
7d2311b1
...
...
@@ 104,6 +104,7 @@ Classical ciphers
### Substitution ciphers

Hill cipher

Polyalphabetic Affine cipher
Utilities
...
...
include/cry/affine.h
View file @
7d2311b1
/*
* 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}
*  RotX : keylen = 1, keya = {1}, keyb = {X}
*  Affine : keylen = 1, keya = {a}, keyb = {0}
*  Vigenere : keylen > 1, keya = {1,...,1}, keyb = {b1,...,bn}
*  PolyAffine: keylen > 1, keya = {a1,...,an}, keyb = {b1,...,bn}
*/
#ifndef CRY_AFFINE_H_
...
...
include/cry/hill.h
View file @
7d2311b1
/*
* 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=<x1,...,xn> and the ciphertext y=<x1...yn>
* 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
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment