Пример #1
0
def speedTest():
    global text, alphabet, frequencyTable
    gammas = (u'ы',
              u'му',
             u'дом',
             u'след',
             u'бочка',
             u'тишина',
             u'молоток',
             u'бензобак',
             u'бомбардир',
             u'бронежилет',
             u'полуавтомат',
             u'спецоперация',
             u'автопогрузчик',
             u'реструктурация')

    gammaRange = range(1, len(gammas[-1]) + 1)

    print 'Starting Time Test for different Gamma lengths [%d...%d]:' % (len(gammas[0]), len(gammas[-1]))
    for g in gammas:
        start = time.clock()
        cipher = crypto.applyGamma(text, g, alphabet)
        crypto.crack(cipher, alphabet, frequencyTable, len(g), output=Gag())
        elapsed1 = time.clock() - start
        start = time.clock()
        crypto.crack(cipher, alphabet, frequencyTable, gammaRange, output=Gag())
        elapsed2 = time.clock() - start
        print '|Gamma| = %d ; Pure time = %fs ; Full time = %fs' % (len(g), elapsed1, elapsed2)

    print 'Done.'
Пример #2
0
def basicTest():
    global text, alphabet
    gamma = u'ссрс'
    start = time.clock()
    cipher = crypto.applyGamma(text, gamma, alphabet)
    crypto.crack(cipher, alphabet, frequencyTable, variants=3, moreInfo=True)
    print 'time = %fs' % (time.clock() - start)
Пример #3
0
def reliabilityTest():
    global text, alphabet, frequencyTable

    gamma = u'йцукенгшщзх'

    print 'Starting Reliability Test for Ciphertexts with different lengths:'
    print '|Gamma| = %d:\n' % len(gamma)

    for l in range(len(text), 0, -10):
        start = time.clock()
        cipher = crypto.applyGamma(text[:l], gamma, alphabet)
        results = crypto.crack(cipher,
                               alphabet,
                               frequencyTable,
                               keyLength=range(1,
                                               len(gamma) + 1),
                               output=Gag())
        reliability = 0
        reliableGamma = ''

        for g, t in results:
            k = similarityPercent(g, gamma)
            if k > reliability:
                reliableGamma = g
                reliability = k

        print 'Cipher length = %d ; Time = %fs ; Gamma = "%s" ; Reliability = %d%%' % (
            len(cipher), time.clock() - start, reliableGamma,
            100 * reliability)

    print 'Done.'
Пример #4
0
def speedTest():
    global text, alphabet, frequencyTable
    gammas = (u'ы', u'му', u'дом', u'след', u'бочка', u'тишина', u'молоток',
              u'бензобак', u'бомбардир', u'бронежилет', u'полуавтомат',
              u'спецоперация', u'автопогрузчик', u'реструктурация')

    gammaRange = range(1, len(gammas[-1]) + 1)

    print 'Starting Time Test for different Gamma lengths [%d...%d]:' % (len(
        gammas[0]), len(gammas[-1]))
    for g in gammas:
        start = time.clock()
        cipher = crypto.applyGamma(text, g, alphabet)
        crypto.crack(cipher, alphabet, frequencyTable, len(g), output=Gag())
        elapsed1 = time.clock() - start
        start = time.clock()
        crypto.crack(cipher,
                     alphabet,
                     frequencyTable,
                     gammaRange,
                     output=Gag())
        elapsed2 = time.clock() - start
        print '|Gamma| = %d ; Pure time = %fs ; Full time = %fs' % (
            len(g), elapsed1, elapsed2)

    print 'Done.'
Пример #5
0
def basicTest():
    global text, alphabet
    gamma = u'ссрс'
    start = time.clock()
    cipher = crypto.applyGamma(text, gamma, alphabet)
    crypto.crack(cipher, alphabet, frequencyTable, variants=3, moreInfo=True)
    print 'time = %fs' % (time.clock() - start)
Пример #6
0
def reliabilityTest():
    global text, alphabet, frequencyTable

    gamma = u'йцукенгшщзх'

    print 'Starting Reliability Test for Ciphertexts with different lengths:'
    print '|Gamma| = %d:\n' % len(gamma)

    for l in range(len(text), 0, -10):
        start = time.clock()
        cipher = crypto.applyGamma(text[:l], gamma, alphabet)
        results = crypto.crack(cipher, alphabet, frequencyTable, keyLength=range(1, len(gamma)+1), output=Gag())
        reliability = 0
        reliableGamma = ''

        for g, t in results:
            k = similarityPercent(g, gamma)
            if k > reliability:
                reliableGamma = g
                reliability = k

        print 'Cipher length = %d ; Time = %fs ; Gamma = "%s" ; Reliability = %d%%' % (len(cipher), time.clock() - start, reliableGamma, 100 * reliability)

    print 'Done.'