Exemple #1
0
def allTests():

    encrypteeee = a.encrypt('000000000000000000000000',
                            '000000000000000000000000')
    encrypteeee2 = a.encrypt('000000000000000000000001',
                             '000000000000000000000000')

    decrypteeee = a.decrypt('c213b237dd00caee86bf3d7c',
                            '000000000000000000000000')

    testHexToBin = u.hexToBinery(encrypteeee)
    testHexToBin2 = u.hexToBinery(encrypteeee2)
    xorBinTest = u.xorBinery(testHexToBin, testHexToBin2)

    testBinTOHex = u.bineryToHex(testHexToBin)

    xorhextest = u.xor('a', 'a')

    encryptionDecryptinTest()
    res = ava.avalancheExecute()
    printAvalancheRes(res)
    randomSequencLastBit = inputOrGenerateRandomSequencOfbLastBit(
        const.RANDOM_SEQUENCE_MAX_SIZE)

    nistTestsExec(randomSequencLastBit)

    randomSequenc = inputOrGenerateRandomSequencOfb(
        const.RANDOM_SEQUENCE_MAX_SIZE_OFB_MODE)
Exemple #2
0
def generateRandomeTestSample():
    """
    this function generate array of bytes from encryption alg 
    the output length is 1000 bit
    """
    randomPlainTextArray = [
        random.choice('0123456789abcdef') for n in range(24)
    ]
    randomPlainText = "".join(randomPlainTextArray)

    encryptText = a.encrypt(randomPlainText, const.KEY)
    return randomPlainText, encryptText
Exemple #3
0
def generateRandomeTestSampleOfb(i):
    """
    this function generate array of bytes from encryption alg
    the output length is i*96 bit
    """
    randomPlainTextArray = [random.choice('0123456789abcdef')
                            for n in range(24)]
    randomPlainText = "".join(randomPlainTextArray)
    encryptText = randomPlainText
    randomBitsString = ''

    for n in trange(i):
        encryptText = a.encrypt(encryptText, const.KEY)
        randomBitsString = randomBitsString+u.hexToBinery(encryptText)
    return randomBitsString
Exemple #4
0
def generateRandomeTestSampleOfbLastBit(i):
    """
    this function generate array of bytes from encryption alg
    the output length is 1000 bit
    """
    randomPlainTextArray = [random.choice('0123456789abcdef')
                            for n in range(24)]
    randomPlainText = "".join(randomPlainTextArray)
    encryptText = randomPlainText
    randomBitsString = ''

    for n in trange(i):
        encryptText = a.encrypt(encryptText, const.KEY)
        randomBitsString = randomBitsString+(str(int(encryptText[23], 16) % 2))
    return randomBitsString
Exemple #5
0
def encryptionDecryptinTest():
    print(f.renderText('Enc-Dec  test:'))
    randomPlainText = generateRandomePlainText()
    randomKeyText = generateRandomePlainText()

    print(' plain text is : \t \x1b[1;45;46m' + randomPlainText + '\x1b[0m')
    cipher = a.encrypt(randomPlainText, randomKeyText)
    print(' cipher  is : \t\t \x1b[1;45;48m' + cipher + '\x1b[0m')
    print(' decrypting ...')
    decipher = a.decrypt(cipher, randomKeyText)
    print(' decrypted  is : \t\t \x1b[1;47;42m' + decipher + '\x1b[0m')
    successText = '\x1b[6;30;42m' + 'Success!' + '\x1b[0m'
    failText = '\x1b[6;30;41m' + 'Fail!' + '\x1b[0m'
    if randomPlainText == decipher:
        print(successText)
    else:
        print(failText)
    pass
Exemple #6
0
def avalanchOneStage(basePlainText, baseCipherText):
    """
    this function call in each stage of avalanche test 
    :baseCipherText cipher 
    """
    bineryBasePlainText = list(bin(int(basePlainText, 16))[2:].zfill(96))
    bineryBaseCipherText = list(bin(int(baseCipherText, 16))[2:].zfill(96))
    stage = [[0 for i in range(96)] for n in range(96)]
    for i in range(96):
        toggledBineryPlainText = toggleOneBit(bineryBasePlainText, i)
        toggledBineryPlainTextStr = ''.join(
            str(item) for item in toggledBineryPlainText)
        toggledBineryPlainTextHex = hex(int(toggledBineryPlainTextStr,
                                            2))[2:].zfill(24)
        encryptedToggledP = a.encrypt(toggledBineryPlainTextHex, const.KEY)
        bineryCipherToggled = list(
            bin(int(encryptedToggledP, 16))[2:].zfill(96))
        diff = dif(bineryBaseCipherText, bineryCipherToggled)
        for j in range(96):
            stage[i][j] = diff[j]
    return stage
    pass