Analysis and Design of A ﬃ ne and Hill Cipher

Cryptography is the study of mathematical techniques for all aspects of information security. Cryptanalysis is the complementary science concerned with the methods to defeat these techniques. Cryptology is the study of cryptography and cryptanalysis. The security of information encompasses the following aspects:


Introduction
Cryptography is the study of mathematical techniques for all aspects of information security.Cryptanalysis is the complementary science concerned with the methods to defeat these techniques.Cryptology is the study of cryptography and cryptanalysis.The security of information encompasses the following aspects: • confidentiality or privacy, • data integrity, • authentication, • nonrepudiation.
Each of these aspects of message security can addressed by standard methods in cryptography.Besides exchange of messages, tools from cryptography can be applied to sharing an access key between multiple parties so that no one person can gain access to a vault by any two of them can.Another role is in the design of electronic forms of cash.As we have seen, shift ciphers offer very little security.The problem is that the letter substitutions, or shifts, are not mixed up enough.The idea of an affine cipher is to use multiplication combined with addition, modulo m, where m is an integer, to create a more mixed-up substitution (Barr, 2002).The affine cipher is simply a special case of the more general monoalphabetic substitution cipher.The key for the affine cipher consists of an ordered pair, say (a, b).In selecting the key, it is important to note the following restrictions; a 0 and b must be chosen from among the integers 0, 1, 2, 3, • • • , m − 1 and a 0 must be relatively prime to m (i.e. a should have no factors in common with m).For example, assuming we use a 26 character alphabet (i.e.m = 26), 15 and 26 have no factors in common and therefore 15 is an acceptable value for a.
On the other hand, if we chose 12 for the value of a, it is obvious that 12 would be an unacceptable value since 12 and 26 have common factors, specifically 2. In General, an affine cipher is a cipher system in which plaintext letters are enciphered mathematically by the function, y = ax + b mod m and using function notation, we have, ϵ(x) = ax + b mod m where x is the numerical equivalent of the plaintext letter and m is the number of letters in the alphabet.
Encryption = the process of disguising a message so as to hide the information it contains; this process can include both encoding and enciphering (see definitions below).
Protocol = an algorithm, defined by a sequence of steps, precisely specifying the actions of multiple parties in order to achieve an objective.
Plaintext = the message to be transmitted or stored.
Ciphertext = the disguised message.
Alphabet = a collection of symbols, also referred to as characters.
Character = an element of an alphabet.
Bit = a character 0 or 1 of the binary alphabet.
String = a finite sequence of characters in some alphabet.
Example 1 The following are some standard alphabets.
A, Decode = to convert the encoded message back to its original alphabet and original form the term plaintext will apply to either the original or the encoded form.The process of encoding a message is not an obscure process, and the result that we get can be considered equivalent to the plaintext message.
Cipher = a map from a space of plaintext to a space of ciphertext.
Encipher = to convert plaintext into ciphertext.
Decipher = to convert ciphertext back to plaintext.
Stream cipher = a cipher which acts on the plaintext one symbol at a time.
Block cipher = a cipher which acts on the plaintext in blocks of symbols.
Substitution cipher = a stream cipher which acts on the plaintext by making a substitution of the characters with elements of a new alphabet or by a permutation of the characters in the plaintext alphabet.
Transposition cipher = a block cipher which acts on the plaintext by permuting the positions of the characters in the plaintext.
Example 2 The following is an example of a substitution cipher: which takes the plaintext BAD CAFE BED to the ciphertext CPOS ANSNO.

Cryptosystems
Given an alphabet A we define A * to be the set of all strings over A. In order to define a cryptosystem, we require a collection of sets: where M is a subset of A * , C is a subset of A ′ * , and K and K ′ are sets which are generally strings of fixed finite length over some alphabets (e.g.A n or A ′n ).A cryptosystem or encryption scheme is a pair (E, D) of maps for all M in M. We write E K for the map E(K, .): M → C and similarly write D K ′ for D(K ′ , .): C → M. With this notation the condition on E, D, K and K ′ is that D K ′ oE K is the identity map on M.
We will refer to E K as a cipher, and note that a cipher is necessarily injective.For many cryptosystems, there will exist a unique inverse ciphertext key K ′ associated to each plaintext key K.A cryptosystem for which the inverse key K ′ is K itself (hence K = K ′ ) is said to be symmetric.If the inverse key K ′ associated to K is neither K itself nor easily computable function of K, then we say that the cryptosystem is asymmetric or a public key cryptosystem.
A fundamental principle of cryptography is that the security of a cipher E K (i.e. the difficulty in finding D K ′ ) does not rest on the lack of knowledge of the cryptosystem (E, D).Instead, security should be based on the secrecy of K ′ .Recall that a (cryptographic) protocol is an algorithm, defined by a sequence of steps, precisely specifying the actions of multiple parties in order to achieve a (security) objective.An example of a cryptographic protocol, we describe the steps for message exchange using a symmetric key cryptosystem.
• Alice and Bob publicly agree on a cryptosystem (E, D).
• For each message M Alice→ Bob: The difficulty of step 2.a was one of the fundamental obstructions to cryptography before the advent of public key cryptography.Asymmetric cryptography provides an elegant solution to the problem of distribution of private keys.

Affine Cipher
Another type of substitution cipher is the affine cipher (or linear cipher).Even though affine ciphers are examples of substitution ciphers, and are thus far from secure, they can be easily altered to make a system which is, in fact, secure.To set up an affine cipher, you pick two values a and b, and then set ϵ(m) = am + b mod 26.For example, if we take a = 3 and b = 8, then the encryption function is ϵ(m) = 3m + 8 mod 26.
To encrypt the letter C, we first note that C corresponds to the number 02.Plugging this in for m, we get ϵ(02) = 3(02) + 8 = 14, and so C is encrypted as O.To find our decryption function, we set s = ϵ(m) and solve for m in terms of s.We have: Since gcd (3, 26) = 1, we know that there will be an x with 3x ≡ 1 mod 26.We could use the Extended Euclidean Algorithm to find x, or we can simply notice that (3) (9) = 27 ≡ 1 mod 26 and so x = 9 works.Now we multiply both sides by 9: (2) you and your partner will decipher the message that the other team gave you.Using their values of a and b, decode their message using δ(s) = x(s − b) mod 26, where x satisfies ax ≡ 1 mod 26.
As we mentioned earlier, affine ciphers are not secure because they're really just special examples of substitution ciphers and so one may use "frequency analysis" to crack them.However, we can tweak the idea a bit and consider affine block ciphers instead.The mathematics is the same, only now instead of encrypting one letter at a time, we encrypt a block of letters together.As an example, suppose we want to take our block-length to be 4.This means that we divide our message into blocks of 4 letters and encrypt each block separately.The largest number we could end up with is 456,975 (corresponding to the highly unlikely 4-letter block "ZZZZ"), and so we need to be sure that our modulus is greater than 456,975.We could use 456,976 but it's just as easy (if not easier) to use 1,000,000.Now we proceed just as before.
We choose a and b and set ϵ(m) = am + b mod 1, 000, 000.As long as we've chosen a so that gcd(a, 1, 000, 000) = 1, we can find an integer x such that ax ≡ 1 mod 1, 000, 000.In this case, our decryption function is δ(s) = x(s − b) mod 1, 000, 000.Because we're now encrypting blocks of letters rather than single letters, frequency analysis will not work here.In other words, affine block ciphers are reasonably secure as long as the block size is large enough (blocks of size four will most likely be big enough).Even though affine block ciphers are secure, there's still a problem with them.
The problem is that they're symmetric.This means that anyone who knows the encryption function ϵ(m) also knows (or can easily figure out) the decryption function δ(s).For example, all one needs to do to figure out the formula for δ(s) given that ϵ(m) = am+b mod 1, 000, 000 is use the Extended Euclidean Algorithm to find x such that ax ≡ 1 mod 1, 000, 000.This is easy to do either by hand or with the help of a computer.
Example 3.3 Suppose we want to set up correspondence where a message is encrypted with the key (7, 11) and using a twenty-six letter alphabet.Substituting our given key and modulus into the Affine Cipher encryption function, we have ϵ(x) = 7x + 11 mod 26.Then, using Table 1,  Finally, we translate the encrypted integers back into letters using Table 1 and get LOOLZD.
All of the examples presented thus far have been calculated modulo 26, with the numbers 0 thru 25 corresponding to letters A thru Z respectively.When we take into consideration using lower case, upper case, punctuation, and other symbols, more numbers are required.To help us define alphabets other than the standard twenty-six letter upper case alphabet, we will employ shifted ASCII codes, which are numerical values assigned to every character on a computer keyboard, to generate three additional alphabets, specifically, the Mod 29 alphabet, which is formed from the mod 26 alphabet by adding a space, period, and question mark, the Mod 89 alphabet, which are the ASCII codes of a certain 89 characters shifted left 34 units, and the Mod 95 alphabet, which are the ASCII codes shifted left 32 units.
Note 3.4 Each of these additional alphabets are located in Appendix [2, A].

<Table 1>
Decryption of the ciphertext obtained by applying the Affine Cipher encryption function can be accomplished similar to the encryption process.However, as we seen with the Shift Cipher, we must first perform the steps, learned in algebra, to find the inverse function.As we previously stated, the Affine Cipher consists of both multiplication and addition and unlike the Shift Cipher, it is necessary to define the multiplicative inverse of an integer a modulo m.
Note 3.5 For the purposes of this project, the multiplicative inverses of invertible elements in the alphabets modulo 26, 29, 89, and 95 will be supplied in Appendix [2, B].However, there is a process that can be used to calculate the multiplicative inverse, generally seen in Discrete Mathematics and Number Theory, known as the Euclidean Algorithm.
Example 3.6 Using the derived decryption function for the Affine Cipher, let us decipher the ciphertext, LOOLZD, from the previous example to ensure we get the correct plaintext.Our plaintext was encrypted using a key of (7,11), where a = 7 and b = 11, and therefore we must first find 7 −1 modulo 26.
By Table 2, 7 −1 = 15, so our decryption formula will be Finally, the last step is to translate the decrypted integers back into letters using Table 1, and get ATTACK.

<Table 2>
Now suppose we want to encrypt a message twice.Suppose we use the mod 95 alphabet in Appendix [2, A], we would then need to select two separate keys, say (17, 62) and (9, 24).Substituting our two keys and the selected modulus into the Affine Cipher encryption function, we get two functions g and h as follows g(x) = 17x + 62 mod 95, h(x) = 9x + 24 mod 95.
Using the same process as the previous example, let us encrypt the message, Retreat NOW!, first using function g and then h.Do note, since we are using a 95 character alphabet, we must take into account using lower and upper case letters, punctuation, and empty spaces.Using Mod 95 Alphabet, in Appendix [2, A], the numerical equivalents of Retreat NOW! are 50,69,84,82,69,65,84,0,46,47,55,1 and encrypting the message by first using g we get Since we are calculating modulo 95, all integer values must be reduced modulo 95.Hence, our new function composition is f (x) = 58x + 12 mod 95.
Next, we will use the integer values found using h −1 and substitute them into g −1 as follows Introduced in 1929 by Lester Hill, the Hill cipher is a poly-alphabetic cipher that uses matrices to encode plaintext messages.The key for this cipher system consist of an n × n square invertible matrix A, where the larger the dimensions the more secure the encryption will be.To ensure the key matrix A is invertible it is important to note that the determinant of A, det(A) , must be relatively prime to the modulus m.The basic idea of the Hill cipher is to put the letters of the plaintext into blocks of length n, assuming an n × n key matrix, and then each block of plaintext letters is then converted into a column matrix of integers according to the alphabet chosen and then pre-multiplied by the n × n key matrix.The results are then converted back to letters and the ciphertext message is produced.Due to the complexity of working with large matrices, we will stick with using a 2 × 2 matrix ] modulo 26.The first step is to assign each letter of the plaintext its numerical equivalent, using Table 1, which are 19, 17, 14, 9, 0, 13.
In the event that the length of the plaintext is not a multiple of the size of the key matrix, random letters can be added to the end of the plaintext.We then perform matrix multiplication as follows This corresponds to the letter sequence UDBINA.
As previously stated, when selecting a key matrix A it is imperative that it be invertible.To determine if the key matrix A is invertible, the det(A) must be relatively prime to the modulus m.By definition of an inverse matrix, the inverse of a matrix must be a matrix such that when multiplied by the original matrix, or key matrix in our case, the product yields the identity matrix There are at least a couple techniques for finding the inverse of an invertible matrix, whose entries come from a ring < Z, +, • >, where + denotes addition modulo m and • denotes multiplication modulo m.It is possible to use a modified Gauss-Jordan method for finding inverses of 2 × 2 invertible matrices.For a 2 × 2 invertible matrix, The numerical equivalents of the calculated plaintext is 19, 17, 14, 9, 0, 13, and converting each calculated integer to its respective letter using Table 1 we obtain

T ROJAN.
The Hill cipher is an excellent application that enables students to practice matrix operations in an interesting and exciting way.As with the previous examples of classical ciphers, it is assumed that the student is familiar with each classical cipher's respective mathematical process.

Conclusion and Further Research
All our previous results show that the concepts of affine and Hill cipher in this paper can constitute a significant aspect of computer and information science.It is clear that its study started here can successfully be extended to cipher systems in which plaintext letters are enciphered mathematically by a liner function.This will surely be subject of some further research.
Finally, we mention an open problems concerning to this topic.
Problem 5.1 How can be generalized the affine cipher in which plaintext letters are enciphered mathematically by the function, f (X) = AX + B mod m where X, B are column matrixes and A is a n × n square matrix and m is the number of letters in the alphabet?
a) Alice and Bob agree on a secret key K. b) Alice computes C = E K (M) and sends it to Bob. c) Bob computes M = D K (C) to obtain the plaintext.
26, so 3m ≡ s − 8 mod 26 Definition 3.1 (Barr, 2002) A multiplicative inverse of an integer a modulo m is an integer b, in the range 1 to m − 1, such that ab ≡ 1 mod m.When a and m are relatively prime, such ab will exist and we call b the multiplicative inverse of a and label it a −1 .
27m ≡ 9(s − 8) mod 26 ≡ 9s − 72 mod 26 ≡ 9s + 6 mod 26, which tells us that m = δ(s) = 9s + 6 mod 26.In general, to construct an affine cipher, we begin by choosing a and b with gcd(a, 26) = 1.Then ϵ(m) = am + b mod 26 and δ(s) = x(s − b) mod 26, where x satisfies ax ≡ 1 mod 26.Exercise 3.2 This exercise has two parts.Working in teams of 2, (1) you and your partner will create an affine cipher by choosing a and b with gcd(a, 26) = 1.Using your cipher, ϵ(m) = am + b mod 26, encode a message that is between 8 and 12 letters long.Give this encoded message, along with your values of a and b, to another team to decipher.

Table 1 .
The integers corresponding to the twenty-six letter