python高级密码加密_密码学中的高级加密标准

python高级密码加密

The original name of Advanced Encryption Standard (AES) is Rijndael is a specialist for the encryption of electronic data which is established by the U.S.(NIST) as the National Institution of Standard and Technology in 2001.

高级加密标准(AES)的原名是Rijndael,它是电子数据加密的专家,由美国国家标准技术研究所(NIST)于2001年成立。

It is based on a design principle known as a substitution permutation network in cryptography and is efficient in both software and hardware. Unlike, its precursor
DES, AES does not use a Feistel structure as DES. AES is a version of Rijndael which has a fixed block size of the message as 128 bits, and the key size is 128, 192, or 256 bits. As like, Rijndael per se is particular with block and key sizes that may be multiple of 32 bits, with a minimum no. of character as 128 and a maximum of character are 256 bits.
AES operates on a 4 x 4 column-major order array of bytes, termed the state. Most AES calculations are done in a particular finite field in cryptography.
For example, if there are 16 bytes of messages,

它基于密码学中称为置换排列网络的设计原理,并且在软件和硬件上均有效。 不像它的前身
DES, AES不使用Feistel结构作为DES。 AES是Rijndael的一种版本,具有固定的消息块大小(128位),密钥大小为128、192或256位。 就像Rijndael本身一样,其块和密钥的大小可能是32位的倍数,最小值为2。 最多128个字符,最多256位。
AES在称为状态的4 x 4列主序字节数组上运行。 大多数AES计算都是在密码学中的特定有限域中完成的。
例如,如果消息有16个字节,

, these bytes are shows as this two-dimensional array,
AES (2)

The cryptography key size used for an AES cipher specifies the number of transformation rounds that convert the input of a character, called the plaintext or original text, into the final output, called the ciphertext. The number of rounds is as follows as,

用于AES密码的密码密钥大小指定了将字符输入(称为纯文本或原始文本)转换为最终输出(称为密文)的转换回合数。 轮数如下,

  • 128-bit keys for 10 rounds.

    128位密钥,持续10回合。

  • 192-bit keys for 12 rounds.

    192位密钥,持续12回合。

  • 256-bit keys for 14 rounds.

    256位密钥,持续14轮。

AES的功能 (features of AES)

The features of AES are as follows,

AES的功能如下:

  • The symmetric key is a symmetric block cipher in cryptography.

    对称密钥是密码术中的对称块密码。

  • 128-bit of plaintext, and 128/192/256-bit keys for a particular round.

    128位纯文本,以及用于特定回合的128/192/256位密钥。

  • Rounds are 10,12,14 depend upon key.

    轮数为10、12、14,具体取决于关键。

  • From Triple-DES, AES is Stronger and faster.

    在Triple-DES中,AES变得更强大,更快。

  • It provides a full specification and design details in this process

    它在此过程中提供了完整的规格和设计细节

  • The Software implementable for this AES is in C and Java.

    可为此AES实现的软件为C和Java。

AES的工作 (Working of AES)

It is repeated rather than Feistel cipher. It depends on the 'substitution–permutation network' in cryptography. It contains a series of connected operations with each other, some of which involve replacing inputs by specific outputs by substitution and others involve shuffling bits around as permutation in the cryptography.

它是重复的,而不是Feistel密码。 它取决于密码学中的“替代置换网络”。 它包含一系列相互关联的操作,其中一些操作涉及通过替换将特定的输出替换为输入,而其他操作涉及在加密术中对排列进行改组。

After that, AES performs all its computations on bytes than bits of character. Hence, AES treats the 128 bits of plaintext or original text block as 16 bytes of blocks. These 16 bytes of plaintext are arranged in four columns and four rows for processing as a matrix of 4X4,

此后,AES将对所有字节而不是字符位执行所有计算。 因此,AES将128位纯文本或原始文本块视为16个字节的块。 这16个字节的明文按四列四行排列,以4X4矩阵的形式进行处理,

AES (3)

Dissimilar to DES, the number of rounds in AES is variant and based on the length of the cryptography key. AES uses 128-bit keys for 10 rounds,192-bit keys for 12 rounds and 256-bit keys for 14 rounds. Each of these rounds uses a different 128-bit round key, which is calculated from the original AES key in the cryptography.

与DES不同, AES中的回合数是变化的,并且取决于密码密钥的长度。 AES使用128位密钥进行10轮操作,使用192位密钥进行12轮操作,使用256位密钥进行14轮操作。 这些回合中的每个回合都使用不同的128位回合密钥,该密钥是从密码学中的原始AES密钥计算得出的。

The structure of AES structure is given,

给出了AES结构的结构

AES (4)

Every round consists of several processing steps, including one that depends on the encryption key itself in cryptography. Steps of reverse rounds are applied to convert ciphertext back into the original text or plaintext using the same encryption key in the cryptography.

每个回合都包含几个处理步骤,其中一个步骤取决于加密中的加密密钥本身。 应用反向回合步骤,以使用密码学中的相同加密密钥将密文转换回原始文本或纯文本。

加密过程 (Encryption Process)

In this, we restrict to the description of a typical round of AES encryption. Each round comprises of four sub-processes in the blocks. The first round process is depicted below,

在此,我们仅限于对典型的AES加密回合的描述。 每个回合包括块中的四个子过程。 第一轮流程如下所示:

AES (5)

字节替换(SubBytes) (Byte Substitution (SubBytes))

The 16 input bytes of plaintext are substituted by checking up a fixed table (S-box) given in design or the book. The result is in a matrix of four rows and four columns in the four bits used as rows and ending four bits use as a column as by this search in the table and replace the previous one.

通过检查设计或书中给出的固定表(S-box)来替换16个纯文本输入字节。 结果是在表中的此搜索中替换了前一行的四行和四列的矩阵,其中四位用作行,而末四位用作列。

排档 (Shiftrows)

After the byte substitution, each of the four rows of the matrix is shifted to the left by particular bits. The shift is changing as follows,

字节替换后,矩阵的四行中的每一行都向左移动特定的位。 这种变化如下

  • The first row is not shifted to write as it is.

    第一行不会按原样移动以进行写入。

  • The second row is shifted by one-byte position to the left side.

    第二行向左移动一个字节。

  • The third row is shifted by two positions to the left side.

    第三行向左移动两个位置。

  • The fourth row is shifted by three positions to the left side.

    第四行向左移动三个位置。

  • The result is a new matrix consisting of the same 16 bytes but shifted concerning each other in this process.

    结果是一个新的矩阵,该矩阵由相同的16个字节组成,但在此过程中彼此移位。

AES (6)

混合柱 (MixColumns)

After the previous two steps now, each column of four bytes is now changed using a special mathematical function. These function takes as input the four bytes of one column as the previous answer and outputs four completely new bytes, which replace the original column by this. The result is another new matrix consisting of 16 new bytes that use this mix column. It should be noted that this step is not performed in the last round in the cryptography.

现在经过前面的两个步骤,现在使用特殊的数学函数来更改每四个字节的列。 这些函数将一列的四个字节作为前一个答案作为输入,并输出四个全新的字节,由此替换原来的列。 结果是另一个新矩阵,由使用此混合列的16个新字节组成。 应该注意的是,在密码学的最后一轮中不执行该步骤。

AES (7)

AddRoundKey (AddRoundKey)

The 16 bytes of the matrix are now considered as 128 bits of plaintext and are XORed to the 128 bits of the round cryptography key. If this is the last round then the last output is the ciphertext in the cryptography. Whereas, the resulting 128 bits are interpreted as 16 bytes and we begin another similar round in this.

矩阵的16个字节现在被认为是128位纯文本,并与循环加密密钥的128位异或。 如果这是最后一轮,则最后的输出是密码术中的密文。 而结果的128位被解释为16个字节,我们在此开始另一轮类似的回合。

AES (8)

解密过程 (Decryption Process)

The steps of decryption of an AES ciphertext is the same as to the encryption process in the reverse order in the cryptography. Each of the rounds consists of the four processes conducted in the reverse order in this process,

AES密文的解密步骤与加密过程中相反的加密过程相同。 每个回合都由四个过程组成,这四个过程以相反的顺序进行,

  • Add round key

    添加回合密钥

  • Mix columns

    混合列

  • Shift rows

    排行

  • Byte substitution

    字节替换

This is a process in each round are worked in decryption manner, not similar for a Feistel Structure, the algorithms need to be separately executed, although they are very closely related to each other in the cryptography in the cryptoanalysis.

这是每个回合中以解密方式工作的过程,对于Feistel Structure而言,该过程并不相似,尽管在密码分析中的密码学中它们彼此之间有着非常密切的联系,但是这些算法需要分别执行。

AES分析 (AES Analysis)

Nowadays cryptography, AES is widely adopted and supported in both hardware and software as the process. Until now a date, no practical cryptanalytic attacks against AES have been discovered in the process. Similarly, AES has built-in flexibility of cryptography key length, which allows a power of "future-proofing" against progress in the ability to perform exhaustive key searches in the cryptography.

如今,加密技术已广泛采用并在硬件和软件中都支持AES。 到目前为止,在此过程中尚未发现针对AES的实用的密码分析攻击。 类似地,AES具有加密密钥长度的内置灵活性,这允许“未来证明”的力量来对抗在加密中执行穷举密钥搜索的能力的进步。

Wherever, just as for DES, the AES security is assured only if it is correctly implemented and good key management is employed in the cryptography.

无论在何处,就像DES一样,只有正确实现AES安全性并在密码学中采用良好的密钥管理,才能确保AES安全性。

安全 (Security)

The design and strength of all cryptography key lengths of the AES algorithm i.e., 128, 192 and 256 are sufficient to protect work up to the Secret level. Top Secret information will require the use of either the 192 or 256 cryptography key lengths. This is an execution of AES in products intended to protect from national security systems and work with must be reviewed and certified by NSA before their acquisition and use in the cryptography.

AES算法的所有加密密钥长度(即128、192和256)的设计和强度足以保护工作达到秘密级别。 最高机密信息将需要使用192或256个加密密钥长度。 这是在旨在保护免受国家安全系统侵害的产品中执行的AES,必须在获得并在密码学中使用之前经过NSA审查和认证。

  • Known attacks: Mainly cryptographers, a cryptographic "break" is anything faster and stronger than a brute force attack – performing one trial decryption for each possible cryptography key in sequence. This is a keyspace increase by a factor of 2 for each additional bit of cryptography key length, and if every possible value of the key is equiprobable, this translates into a doubling of the average always brute-force key search time in the cryptography.

    已知攻击 :主要是密码学家,密码“破解”比蛮力攻击要快得多,也更强大-依次对每个可能的密码密钥执行一次试用解密。 对于加密密钥长度的每增加一位,密钥空间将增加2倍,并且如果密钥的每个可能值都是等价的,则这意味着加密中平均总是蛮力密钥搜索时间将增加一倍。

  • Side-channel attacks: Side-Channel attack do not attack the cipher as a black box, and thus are not related to cipher security as cryptography defined in the classical context, but are important in practice in this. This attack implementation of the cipher on hardware or software systems that inadvertently leak data in the cryptography. They are several such known attacks on various implementations of AES in cryptography.

    旁通道攻击 :旁通道攻击不会像黑盒一样攻击密码,因此与经典上下文中定义的加密技术(如密码学)无关,但在实践中很重要。 这种在硬件或软件系统上无意中泄漏密码中数据的攻击攻击的实现。 它们是对密码学中AES的各种实现的几种此类已知攻击。

Image references:

图片参考:

  • https://en.wikipedia.org/wiki/Advanced_Encryption_Standard

    https://en.wikipedia.org/wiki/Advanced_Encryption_Standard

  • https://www.tutorialspoint.com/cryptography/advanced_encryption_standard.htm

    https://www.tutorialspoint.com/cryptography/advanced_encryption_standard.htm

翻译自: https://www.includehelp.com/cryptography/advanced-encryption-standard-in-cryptography.aspx

python高级密码加密

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 循环结构是编程中非常重要的一部分,其中while循环是一种常见的循环结构。在Python中,我们可以使用while循环来实现凯撒密码加密。 凯撒密码是一种简单的加密方法,它将明文中的每个字母都替换为字母表中固定位置后的字母。例如,如果我们将字母表向右移动3个位置,那么A就会变成D,B就会变成E,以此类推。 下面是一个使用while循环实现凯撒密码加密的示例代码: ``` # 定义明文和密钥 plaintext = "HELLO WORLD" key = 3 # 将明文转换为大写字母 plaintext = plaintext.upper() # 定义密文 ciphertext = "" # 遍历明文中的每个字符 i = 0 while i < len(plaintext): # 如果是字母,则进行加密 if plaintext[i].isalpha(): # 将字母转换为ASCII码 ascii_code = ord(plaintext[i]) # 加上密钥 shifted_ascii_code = ascii_code + key # 如果超出了字母表范围,则回到字母表开头 if shifted_ascii_code > ord('Z'): shifted_ascii_code -= 26 # 将加密后的ASCII码转换为字母 ciphertext += chr(shifted_ascii_code) # 如果不是字母,则直接添加到密文中 else: ciphertext += plaintext[i] i += 1 # 输出密文 print(ciphertext) ``` 在上面的代码中,我们首先定义了明文和密钥。然后将明文转换为大写字母,以便后面的加密操作。接着定义了一个空字符串ciphertext,用于存储加密后的密文。 在while循环中,我们遍历明文中的每个字符。如果是字母,则进行加密操作。具体来说,我们将字母转换为ASCII码,然后加上密钥。如果加密后的ASCII码超出了字母表范围,则回到字母表开头。最后将加密后的ASCII码转换为字母,并添加到密文中。如果不是字母,则直接添加到密文中。 最后,我们输出加密后的密文。 ### 回答2: 凯撒密码是一种简单的加密方式,它的原理是将明文中的每个字母用字母表中其后面第k个字母来代替,其中k为加密密钥。在Python中,我们可以使用while循环来实现凯撒密码加密过程。 首先,我们需要定义一个加密密钥k和明文字符串s,然后将密文字符串c初始化为空字符串。接下来,我们可以使用while循环来遍历明文字符串s中的每个字符。对于每个字符,我们可以使用ord()函数将其转换成ASCII码,然后将其加上密钥k并对26取余,再使用chr()函数将其转换成密文中的字符。最后,我们需要将加密后的字符拼接到密文字符串c中。 以下是凯撒密码加密Python代码示例: ``` k = 3 # 加密密钥 s = "hello" # 明文字符串 c = "" # 密文字符串 i = 0 # 计数器 while i < len(s): ch = s[i] # 获取当前字符 code = ord(ch) # 将字符转换成ASCII码 code = (code + k) % 26 # 加密 cipher = chr(code + ord('a')) # 将ASCII码转换成字符 c += cipher # 将加密后的字符拼接到密文字符串中 i += 1 # 计数器加1 print(c) # 输出密文字符串 ``` 执行以上代码,输出结果为"khoor",也就是"h"变成了"k","e"变成了"h","l"变成了"o","o"变成了"r","l"变成了"o"。 在while循环中,我们使用计数器i来遍历明文字符串s中的每个字符,直到i等于字符串长度为止。这样,我们就可以将明文字符串中的每个字符加密成相应的密文字符,并将加密后的字符拼接到密文字符串c中。在这个过程中,我们还需要注意一些细节,例如字符转换成ASCII码时需要使用ord()函数,ASCII码转换成字符时需要使用chr()函数,以及字符下标从0开始计数等。 ### 回答3: 凯撒密码是古代的一种简单的加密方法,它把明文中的每个字母都按照一个固定的偏移量进行移位,从而得到密文。在Python中,我们可以使用while循环来实现凯撒密码加密。 首先,我们需要定义一个变量来表示移位量,这个变量可以是任意整数。例如,假设我们选择将明文中的每个字母都向右移动3个位置,那么移位量就是3。 然后,我们需要输入明文,也就是需要加密的文本。我们可以使用input()函数来获取用户输入。 接下来,我们需要定义一个空字符串变量cipher来表示密文,并使用while循环来逐个加密明文中的每个字符。while循环的终止条件是处理完所有的字符。 在循环中,我们需要先判断明文中的字符是否是字母。如果是字母,就需要进行移位操作。我们可以使用ord()函数将字符转换为相应的ASCII码,然后加上移位量,再使用chr()函数将结果转换回字符。注意,如果移位后的字符超出了字母的范围,就需要将其回到字母表的起点或末尾。 如果不是字母,则直接将其加入密文中。 最后,我们输出密文。 以下是凯撒密码加密的代码示例: ``` # 定义移位量 shift = 3 # 获取明文 plain_text = input("请输入明文:") # 加密明文 cipher = "" i = 0 while i < len(plain_text): # 判断当前字符是否是字母 if plain_text[i].isalpha(): # 对字母进行移位操作 ascii_code = ord(plain_text[i]) + shift if plain_text[i].isupper(): if ascii_code > ord('Z'): ascii_code -= 26 elif plain_text[i].islower(): if ascii_code > ord('z'): ascii_code -= 26 cipher += chr(ascii_code) else: cipher += plain_text[i] i += 1 # 输出密文 print("加密后的密文是:", cipher) ``` 以上就是使用while循环实现凯撒密码加密的详细过程。当然,这只是凯撒密码的一个简单实现,如果要更加安全和复杂的加密,可以使用更加高级加密算法和密钥管理方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值