0

Decoded

Affine
A
B

Encoded

Affine
A
B

About Affine Cipher

Affine cipher is one of the single transliteration ciphers that encrypts by replacing the characters in the text with other characters.

Character replacement is performed using the following formula.

E(x) = (ax + b) mod m

m represents the type of character to convert. x is a letter replaced by a number from 0 to m - 1. a and bb are the encryption keys.

For example, for the 26 alphabetic characters "ABCDEFGHIJKLMNOPQRSTUVWXYZ", m = 26 and x is 0 to 25 with A to Z replaced by numbers.

CharacterABCDEFGHIJKLMNOPQRSTUVWXYZ
x012345678910111213141516171819202122232425

If a = 5, b = 3, it will be encrypted in the following flow.

Plain textSECRET
x184217419
(5x + 3)932313882398
(5x + 3) mod 26152313102320
Cipher textPXNKXU

The result of encrypting all letters with a = 5, b = 3 is as follows.

Plain : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: DINSXCHMRWBGLQVAFKPUZEJOTY

Specifying a = 1, b = -3 gives the Caesar cipher, specifying a = 1, b = 13 gives the same result as ROT13, and specifying a = -1, b = -1 gives the same result as the Atbash cipher.

a must specify a number of co-prime with m . This means that the only number that divides a and m must be 1. For example, a = 4, m = 26 cannot be specified because it is divisible by 2 as well as 1. In DenCode, if given an invalid a , it returns the original character without conversion.

Other language support

In addition to Latin letters, Cyrillic and Japanese Hiragana / Katakana are supported.

The results of encryption with a = 5 and b = 3 are as follows.

Cyrillic
Plain : АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ
Cipher: ГИНТЧЬБЖЛРХЪЯДЙОУШЭВЗМСЦЫАЕКПФЩЮ

m = 32 (32 characters).

Japanese Hiragana / Katakana
Plain : ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをんゔ
Cipher: いぉぎこじそぢでぬぱぶほむゅりわゔぅおくごすぞっとねひぷぼめゆるゐぁうかぐさずたつどのびへぽもょれゑあぇがけざせだづなはぴべまゃよろをぃえきげしぜちてにばふぺみやらゎん
Plain : ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲンヴ
Cipher: イォギコジソヂデヌパブホムュリワヴゥオクゴスゾットネヒプボメユルヰァウカグサズタツドノビヘポモョレヱアェガケザセダヅナハピベマャヨロヲィエキゲシゼチテニバフペミヤラヮン

The character order is the Unicode definition order. Please note that "ゕ", "ゖ", "ヵ", "ヶ", "ヷ", "ヸ", "ヹ", and "ヺ" are not subject to encryption.

m = 84 (84 characters).