DES (python)

OF

what?

Symmetric encryption algorithm

why?

How to ensure security?

, The plaintext is encrypted by various permutation operation.

High efficiency of encryption and decryption

== decryption key encryption keys

RSA is how relatively unsafe?

Since the same encryption key and decryption key, the encrypted security is dependent on the security key, the network and the interaction process, complex environment, security is difficult to guarantee the security of the key.

how?

encryption


des 64-bit plaintext grouping operation, by an initial permutation plaintext into left & right half. Followed by 16 identical operation (F), combined with the key data in the course of operation, after 16, the left and right halves joined together, and finally through the end of a permutation (inverse permutation of the initial permutation), the encryption process is completed .

DES mode of operation

mode description use
ECB Independently each plaintext encrypted with the same key Data transmitter (e.g. a cryptographic key)
CBC Different plaintexts encrypted with the previous set of the current input to the algorithm or encryption Transmitting data packets, authentication
CFB Each time only process the input bit will last ciphertext as input to the encryption algorithm generating pseudo random output, then the output current changes XOR the plaintext to produce the ciphertext current Transport stream, certification
OFB Similarly with CFB, and then enter a different encryption algorithm for this is output before the next encryption algorithm There scrambled transport stream channel

Code:

Source http://whitemans.ca/des.html

# encoding: utf-8
import pyDes

# For Python3, you'll need to use bytes, i.e.:
#   data = b"Please encrypt my data"
#   k = pyDes.des(b"DESCRYPT", pyDes.CBC, b"\0\0\0\0\0\0\0\0", pad=None, padmode=pyDes.PAD_PKCS5)

data = "加密Please encrypt my data"
data = bytes(data,encoding='utf-8') #将utf8转化为byte,注意加密的数据必须为byte
k = pyDes.des("DESCRYPT", pyDes.CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=pyDes.PAD_PKCS5)
d = k.encrypt(data)
print("Encrypted: %r" % d)
print("Decrypted: %r" % k.decrypt(d))
assert k.decrypt(d) == data

Guess you like

Origin www.cnblogs.com/Erma/p/12350416.html