Cryptography With Python 简明教程

Multiplicative Cipher

在使用凯撒密码技术时,加密和解密符号涉及使用简单的基本加法或减法程序将值转换为数字。

While using Caesar cipher technique, encrypting and decrypting symbols involves converting the values into numbers with a simple basic procedure of addition or subtraction.

如果使用乘法转换为密码文本,则称为 wrap-around 情况。请将字母和关联的数字考虑为以下所示−

If multiplication is used to convert to cipher text, it is called a wrap-around situation. Consider the letters and the associated numbers to be used as shown below −

associated numbers

这些数字将用于乘法程序,关联密钥为 7。在这种情况下用于生成乘法密码的基本公式如下−

The numbers will be used for multiplication procedure and the associated key is 7. The basic formula to be used in such a scenario to generate a multiplicative cipher is as follows −

(Alphabet Number * key)mod(total number of alphabets)

通过输出获取的数字映射到上面提到的表格中,并且相应的字母被视为加密字母。

The number fetched through output is mapped in the table mentioned above and the corresponding letter is taken as the encrypted letter.

encrypted letter

乘法密码在 Python 中的基本调制函数如下−

The basic modulation function of a multiplicative cipher in Python is as follows −

def unshift(key, ch):
   offset = ord(ch) - ASC_A
   return chr(((key[0] * (offset + key[1])) % WIDTH) + ASC_A)

Note − 乘法密码的优点是它可以使用 8,953,851 之类的非常大的密钥。对于计算机而言,通过九百万个密钥中的大多数进行暴力攻击需要相当长的时间。

Note − The advantage with a multiplicative cipher is that it can work with very large keys like 8,953,851. It would take quite a long time for a computer to brute-force through a majority of nine million keys.