def hackTransposition(message):
    print('Hacking...')
    # Python programs can be stopped at any time by pressing Ctrl-C (on
    # Windows) or Ctrl-D (on Mac and Linux)
    print('(Press Ctrl-C or Ctrl-D to quit at any time.)')

    for key in range(1, len(message)):
        print('Trying key #%s... ' % (key), end='')
        sys.stdout.flush()

        # We want to track the amount of time it takes to test a single key,
        # so we record the time in startTime.
        startTime = time.time()

        decryptedText = transpositionDecrypt.decryptMessage(key, message)
        englishPercentage = round(
            detectEnglish.getEnglishCount(decryptedText) * 100, 2)

        totalTime = round(time.time() - startTime, 3)
        print('Test time: %s seconds, ' % (totalTime), end='')
        sys.stdout.flush()  # flush printed text to the screen

        print('Percent English: %s%%' % (englishPercentage))
        if englishPercentage > 20:
            print()
            print('Key ' + str(key) + ': ' + decryptedText[:100])
            print()
            print('Enter D for done, or just press Enter to continue:')
            response = input('> ')
            if response.strip().upper().startswith('D'):
                return decryptedText
    return None
Example #2
0
    def hackTransposition(message):
        print('Hacking...')

        print('(Press Ctrl-C or Ctrl-D to quit at any time.)')

        for key in range(1, len(message)):
            print('Trying key #%s...' % (key))
            sys.stdout.flush()
            startTime = time.time()
            decryptedText = decryptMessage(key, message)
            englishPercentage = round(
                detectEnglish.getEnglishCount(decryptedText) * 100, 2)

            totalTime = round(time.time() - startTime, 3)
            print('Test time: %s seconds, ' % (totalTime), end='')
            sys.stdout.flush()

            print('Percent English: %s%%' % (englishPercentage))
            if englishPercentage > 20:
                print()
                print('Key ' + str(key) + ': ' + decryptedText[:100])
                print()
                print('Enter D if done, anything else to continue hacking:')
                response = input('> ')
                if response.strip().upper().startswith('D'):
                    return decryptedText
        return None
Example #3
0
def hackTransposition(message):
    print("Hacking...")
    print("(Press Ctrl-C to quit at any time)")

    for key in range(1, len(message) * 2):
        print("Trying key #%s" % (key), end=" ")
        sys.stdout.flush()

        startTime = time.time()

        decryptedText = transpositionDecrypt.decryptMessage(key, message)
        englishPercentage = round(
            detectEnglish.getEnglishCount(decryptedText) * 100, 5)

        totalTime = round(time.time() - startTime, 3)
        print("Test time: %s seconds, " % (totalTime), end="")
        sys.stdout.flush()  # Flush printed text to the screen.

        print("Percent English: %s%%" % (englishPercentage))
        if englishPercentage > 20:
            print()
            print("Key " + str(key) + ": " + decryptedText[:100])
            print()
            print("Enter D if done, anything else to continue hacking:")
            response = input("> ")
            if response.strip().upper().startswith("D"):
                return decryptedText
    return None
def hackSimpleSubDictionary(message):
    print('Hacking with %s possible dictionary words...' % (len(detectEnglish.ENGLISH_WORDS) * 3))

    # Python programs can be stopped at any time by pressing Ctrl-C (on Windows) or Ctrl-D (on Mac and Linux)
    print('(Press Ctrl-C or Ctrl-D to quit at any time.)')

    tryNum = 1

    # brute-force by looping through every possible key
    for key in detectEnglish.ENGLISH_WORDS:
        if tryNum % 100 == 0 and not SILENT_MODE:
            print('%s keys tried. (%s)' % (tryNum, key))

        decryptedText = simpleSubKeyword.decryptMessage(key, message)

        if detectEnglish.getEnglishCount(decryptedText) > 0.20:
            # Check with the user to see if the decrypted key has been found.
            print()
            print('Possible encryption hack:')
            print('Key: ' + str(key))
            print('Decrypted message: ' + decryptedText[:100])
            print()
            print('Enter D for done, or just press Enter to continue hacking:')
            response = input('> ')

            if response.upper().startswith('D'):
                return decryptedText

        tryNum += 1
    return None
def hackTransposition(message):
    print('Hacking...')
    # Python programs can be stopped at any time by pressing Ctrl-C (on
    # Windows) or Ctrl-D (on Mac and Linux)
    print('(Press Ctrl-C or Ctrl-D to quit at any time.)')

    for key in range(1, len(message)):
        print('Trying key # %s... ' % (key), end='')
        sys.stdout.flush()

        # We want to track the amount of time it takes to test a single key,
        # so we record the time in startTime.
        startTime = time.time()

        decryptedText = transpositionDecrypt.decryptMessage(key, message)
        englishPercentage = round(detectEnglish.getEnglishCount(decryptedText) * 100, 2)

        totalTime = round(time.time() - startTime, 3)
        print('Test time: %s seconds, ' % (totalTime), end='')
        sys.stdout.flush()  # flush printed text to the screen

        print('Percent English: %s%%' % (englishPercentage))
        if englishPercentage > 20:
            print()
            print('Key ' + str(key) + ': ' + decryptedText[:100])
            print()
            print('Enter D for done, or just press Enter to continue:')
            response = input('> ')
            if response.strip().upper().startswith('D'):
                return decryptedText
    return None
Example #6
0
def hackVigenere(string):
    #set a accurancy for apply in detectEnglish
    accurancy = 0
    current_acc = 0
    #get some possible key length for decipher key
    poss_KeyLength = keyLengthIC(string, 5)
    for length in poss_KeyLength:
        #get some possible keys by the input some possible key length
        poss_keys = vigenereKeySolver(string, length)

        for key in poss_keys:
            solution = vigenereCipher.decryptMessage(key, string)
            curr_accurancy = detectEnglish.getEnglishCount(solution)
            if curr_accurancy > accurancy:
                accurancy = curr_accurancy
                real_key = key
    return real_key
Example #7
0
def hackVigenere(ciphertext):
    # get 5 most possible keylength
    possible_key_length = keyLengthIC(ciphertext, 5)

    max_acc = 0

    for key_length in possible_key_length:
        # get 10 most possible keys
        possible_keys = vigenereKeySolver(ciphertext, key_length)

        for key in possible_keys:
            decrpted_text = vigenereCipher.decryptMessage(key, ciphertext)
            current_acc = detectEnglish.getEnglishCount(decrpted_text)
            # check whether the current key is the best one
            if current_acc > max_acc:
                max_acc = current_acc
                best_key = key

    return best_key
def hackTransposition(message, blockSize, inByRow=False):
    print('Hacking...')
    # Python programs can be stopped at any time by pressing Ctrl-C (on
    # Windows) or Ctrl-D (on Mac and Linux)
    print('(Press Ctrl-C or Ctrl-D to quit at any time.)')
    keys = list(itertools.permutations(list(range(1,blockSize+1))))
    for key in range(0,  math.factorial(blockSize)):
        print('Trying key #%s... ' % (key), end='')
        print(getKeywordSequence(keys[key]))
        sys.stdout.flush()

        # We want to track the amount of time it takes to test a single key,
        # so we record the time in startTime.
        startTime = time.time()
        decryptedText = decrypt(message,keys[key], inByRow)
        englishPercentage = round(detectEnglish.getEnglishCount(decryptedText) * 100, 2)

        totalTime = round(time.time() - startTime, 3)
        print('Test time: %s seconds, ' % (totalTime), end='')
        sys.stdout.flush() # flush printed text to the screen
        global maximum 
        global maxkey 
        if englishPercentage > maximum:
            maximum = englishPercentage
            maxkey = keys[key]
        print('Percent English: %s%%' % (englishPercentage))
        if englishPercentage > 20:
            print()
            print('Key #' + str(key) + ': ' + decryptedText[:100])
            print()
            print('Key', keys[key] )
            print()
            print('Enter D for done, or just press Enter to continue:')
            response = input('> ')
            if response.strip().upper().startswith('D'):
                return decryptedText
    return None