Affine Cipher

4.5K 32 2
                                    

AFFINE CIPHER
Type: Substitution
(Note: it's formula for encryption is f(x)=(ax+b)mod n, and for decryption is f(y)=a^-1(y-b)mod n, where "a" should be coprime of "n", "x" or "y" corresponds on the position of the letter in the alphabet (see rotation code), and "b" is any value of input, and mod n is the limit of rotation)
Example: (encryption)
Plaintext: AFFINE
a=5, b=8, n=26
F(x)=(ax+b)mod26
A=0, F(0)=(5(0)+8)mod26=8
F=5, F(5)=(5(5)+8)mod26=3­­3
F=5, F(5)=(5(5)+8)mod26=3­­3
I =8, F(8)=(5(8)+8)mod26=4­­8
N=13, F(13)=(5(13)+8)mod26­­=73
E=4, F(4)=(5(4)+8)mod26=2­­8
A=08=I
F=33=H
F=33=H
I =48=W
N=73=V
E=28=C

Ciphertext: IHHWVC
Example: (decryption)
Ciphertext: IHHWVC
a=5, b=8, n=26
F(y)=a^-1(y-b)mod n
I =08, f(8)=5^-1(8-8)mod26=­­0
H=33, f(33)=5^-1(33-8)mod2­­6=5
H=33, f(33)=5^-1(33-8)mod2­­6=5
W=48, f(48)=5^-1(48-8)mod2­­6=8
V=73, f(73)=5^-1(73-8)mod2­­6=13
C=28, f(28)=5^-1(28-8)mod2­­6=4
I =0=A
H=5=F
H=5=F
W=8=I
V=13=N
C=5=E
Plaintext: AFFINE

Codes (Codes And Ciphers)Tahanan ng mga kuwento. Tumuklas ngayon