Exemple #1
0
    def __init__(self):
        self._key = bytes2str(randomBytes(16))

        extraText = '''
Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkg
aGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq
dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUg
YnkK'''
        self._extraText = base64.standard_b64decode(extraText)
        self._aes = AES.new(self._key, AES.MODE_ECB)
Exemple #2
0
	def __init__(self):
		self._key = bytes2str(randomBytes(16))
		
		extraText = '''
Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkg
aGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq
dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUg
YnkK'''
		self._extraText = base64.standard_b64decode(extraText)
		self._aes = AES.new(self._key, AES.MODE_ECB)
Exemple #3
0
def encryptWithRandomKey(data):
	key = bytes2str(randomBytes(16))

	if random.random() < 0.5:
		result = 'ECB'
		aes = AES.new(key, AES.MODE_ECB)
	else:
		result = 'CBC'
		iv = '\x00' * 16
		aes = AES.new(key, AES.MODE_CBC, iv)

	numBytesBefore = random.randrange(5, 10)
	numBytesAfter = random.randrange(5, 10)
	# print numBytesBefore, numBytesAfter
	bytesBefore = bytes2str(randomBytes(numBytesBefore))
	bytesAfter = bytes2str(randomBytes(numBytesAfter))
	
	input = bytesBefore + data + bytesAfter
	input = pkcs7(input, 16)
	# input = data
	output = aes.encrypt(input)
	return output, result
Exemple #4
0
def encryptWithRandomKey(data):
    key = bytes2str(randomBytes(16))

    if random.random() < 0.5:
        result = 'ECB'
        aes = AES.new(key, AES.MODE_ECB)
    else:
        result = 'CBC'
        iv = '\x00' * 16
        aes = AES.new(key, AES.MODE_CBC, iv)

    numBytesBefore = random.randrange(5, 10)
    numBytesAfter = random.randrange(5, 10)
    # print numBytesBefore, numBytesAfter
    bytesBefore = bytes2str(randomBytes(numBytesBefore))
    bytesAfter = bytes2str(randomBytes(numBytesAfter))

    input = bytesBefore + data + bytesAfter
    input = pkcs7(input, 16)
    # input = data
    output = aes.encrypt(input)
    return output, result
Exemple #5
0
	
	groups = list(itertools.izip_longest(*blocks))
	print 'groups:', len(groups)
	print len(groups[0])

	key = []
	decrypted = []
	for group in groups:
		group = list(group)
		while group[-1] is None:
			group.pop()
		
		maxKey, maxBytes, maxScore = crackXor(group)
		key.append(maxKey)
		decrypted.append(maxBytes)
	
	print bytes2str(key)
	
	decBlocks = list(itertools.izip_longest(*decrypted))
	print len(decBlocks)
	print len(decBlocks[0])
	decBytes = []
	for block in decBlocks:
		decBytes.extend(block)
	while decBytes[-1] is None:
		decBytes.pop()
	# print decBytes

	print bytes2str(decBytes)