我正在修读一门关于密码学的课程,我被困在一项任务上.说明如下:
明文plain6.txt已使用DES加密加密6.dat,使用64位密钥作为8个字符的字符串给出(64位,每8位被忽略),所有字符都是字母(小写或更高 - case)和数字(0到9).
要完成分配,请在23.59年2月12日之前将加密密钥发送给我.
注意:我希望得到一个8字节(64位)的密钥.每个字节应该与我的密钥中的相应字节一致,除了在DES中没有使用的最低有效位,因此可以是任意的.
这是我在Python中第一次尝试的代码:
import time
from Crypto.Cipher import DES
class BreakDES(object):
def __init__(self, file, passwordLength = 8, testLength = 8):
self.file = file
self.passwordLength = passwordLength
self.testLength = testLength
self.EncryptedFile = open(file + '.des')
self.DecryptedFile = open(file + '.txt')
self.encryptedChunk = self.EncryptedFile.read(self.testLength)
self.decryptedChunk = self.DecryptedFile.read(self.testLength)
self.start = time.time()
self.counter = 0
self.chars = range(48, 58) + range(65, 91) + range(97, 123)
self.key = False
self.broken = False
self.testPasswords(passwordLength, 0, '')
if not self.broken:
print "Password not …Run Code Online (Sandbox Code Playgroud)