Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

CrypTools/AffineCipher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Usage

Theaffine cipher is a type of monoalphabeticsubstitution cipher. It encrypts a text using anaffine function (f(x) = ax + b).

Detailed Explanations : How it works?

  1. Firstly, each character of the initial text (message to encrypt) is converted in a number from 0 to 25, corresponding to its position in the Latin alphabet which contains 26 letters --> (a = 0, b = 1 ... z = 25 ).

  2. Then, each number obtained is transformed by an affine function (f(x) = ax + b). "x" is representing the number while "a" and "b" are defined during the encryption. "a" and "b" are the keys required to decrypt the final message.

  3. If we take all the images and put them in a list, we obtain n numbers corresponding to n characters of the initial text. The next step consists in finding the values of modulo 26 of each number. (Modulo means remainder)

Example : Modulo 4 of 19 is3 because 15 = 4 * 4 +3 In the other hand, modulo 26 of 26 is0 because 26 = 26 * 1 +0

  1. Therefore, we obtain a new list with n element, each between 0 and 25 both included. All these numbers are converted in letters of the Latin Alphabet using the tables below.

  2. We finally create the final message by putting all the letters side by side.

Steps 1 and 4 can be done with these tables :

ABCDEFGHIJKLM
0123456789101112
NOPQRSTUVWXYZ
13141516171819202122232425

Weaknesses

  • As each letter is encrypted using the same function, trying many possibilities for a or b can be useful to decrypt the message. This is called thebruteforce method.

  • We can also usefrequency analysis if the message is long to decrypt the message as the most common letters in english are :

  • Other possibilities include guessing the keys a and b.

  • Knowing a can be helpful to eliminate a lot of solutions.

Example

Encrypting

  • Message to encrypt :ATTACK
  • Function used : f(x) =3x + 6
  • That means thata = 3 and b = 6

Using the above tables, ATTACK can be written as :0 19 19 0 2 10Images of each number :

  • f(0) = 6
  • f(19) = 63
  • f(2) = 12
  • f(10) = 36

The new list is :6 63 63 6 12 36

Using themodulo 26 method, we obtain:

  • Mod(6,26) = 6
  • Mod(63,26) = 11
  • Mod(12,26) = 12
  • Mod(36,26) = 10

The final message is6 11 11 6 12 10 and using the tables again, we convert them in the encrypted message :

GLLGMK

ATTACK is encrypted with the function3x + 6 and becomesGLLGMK.

Decrypting

  • Message to decrypt :GLLGMK
  • That means thata = 3 and b = 6
  • Hence a-1 =modular multiplicative inverse of a modulo m (m = 26), a-1 = 9
  • Function used : f(x) =9x - 54

Using the above tables, GLLGMK can be written as :6 11 11 6 12 10Images of each number :

  • f(6) = 54 - 54 = 0
  • f(11) = 99 - 54 = 45
  • f(12) = 108 - 54 = 54
  • f(10) = 90 - 54 = 36

The new list is :0 45 45 0 54 36

Using themodulo 26 method, we obtain:

  • Mod(0,26) = 0
  • Mod(45,26) = 19
  • Mod(54,26) = 2
  • Mod(36,26) = 10

The final message is0 19 19 0 2 10 and using the tables again, we convert them in the plain text :

ATTACK

GLLGMK is decrypted with the functionf(x) = 3x + 6 and becomesATTACK.


[8]ページ先頭

©2009-2025 Movatter.jp