Exemplo n.º 1
0
def inp_lst(prompt, lst):
    '''Works like input but accepts only values in the list lst, reask if not.'''

    c = ''
    c = cl_inp(prompt)

    while c not in lst:
        cl_out(c_error, '\nWhat you entered is NOT in list !')
        c = cl_inp(prompt)

    return c
Exemplo n.º 2
0
def use_open_w():  #todo: move (in the console file) and improve this
    try:
        file_name = cl_inp(tr("Enter the wordlist's name :"))
        wordlist_f = open(file_name, 'r')

    except FileNotFoundError:
        cl_out(c_error,
               tr('No file of this name !!!') + ' \n' + tr('Back menu ...'))

    else:
        wordlist_f.close()
        open_w(file_name)
Exemplo n.º 3
0
def use_hasher():
    '''Use hasher function in console mode.'''

    h_str = tuple(algorithms_available)
    prompt_h = set_prompt(algorithms_available)
    prompt = 'Hashes :\n\n ' + prompt_h + '\n\nChoose a hash to hash with :'

    h = inp_lst(prompt, h_str)

    txt = cl_inp('Word to hash :')

    prnt = '=====> ' + hasher(h, txt)
    cl_out(c_output, prnt)
Exemplo n.º 4
0
def inp_int(prompt, type_=int):
    '''Works like input but accepts only type_, reask if not.'''

    while True:
        try:
            var = cl_inp(prompt)
            var = type_(var)

        except ValueError:
            cl_out(c_error, 'What you entered is NOT an {} !'.format(type_))

        else:
            break

    return var
Exemplo n.º 5
0
def use(phoneNumbers=[]):

    lr = False  # Line return

    ret = ''

    if phoneNumbers == []:
        answer = cl_inp(tr('Enter french phone number(s) ("," between) :'))
        phoneNumbers = answer.split(',')
        lr = True

    L = analyze(phoneNumbers)

    for k in L:
        if lr:
            ret += '\n'
        else:
            lr = True

        if len(k['Phone number']) != 10:
            ret += '\n' + tr('Phone number :') + ' ' + k['Phone number']
        else:
            ret += '\n' + tr('Phone number :') + ' ' + k['Phone number'][
                0:2] + ' ' + k['Phone number'][2:4] + ' ' + k['Phone number'][
                    4:6] + ' ' + k['Phone number'][6:8] + ' ' + k[
                        'Phone number'][8:10]

        if k['Recognized']:
            if k['Phone type'] == 'Home phone':
                ret += '\n' + tr('Home phone')
                ret += '\n' + tr(k['Big area'])

            elif k['Phone type'] == 'Cellphone':
                ret += '\n' + tr('Cellphone')

            ret += '\n' + tr('Block') + ' : ' + k['Block']
            ret += '\n' + tr('Area') + ' : ' + k['Area']
            ret += '\n' + tr('Operator') + ' : ' + k['Operator']
            ret += '\n' + tr('Allocation date') + ' : ' + k['Allocation date']
        else:
            ret += '\n' + tr('Unassigned or unrecognized')

    return ret[1:]
Exemplo n.º 6
0
def use(cracker=cracker):
    """Use prima fonctions. Beautiful menu thanks to Lasercata"""

    c = ''
    while c not in ('0', 'quit', tr('exit'), 'q'):

        if cracker: color(c_succes)
        print('')
        print('\\' * 50)

        if cracker: color(c_prog)
        print('\n' + tr('Prima menu :') + '\n')

        if cracker:
            color(c_error)
            print('    0.' + tr('Main menu'))
        else:
            print('    0.' + tr('Exit'))

        if cracker: color(c_succes)
        print('    ' + '-' * 16)
        if cracker: color(c_wrdlt)

        print('    ' +
              tr('Decomposition of a number as a product of prime factors'))
        if cracker: color(c_ascii)
        print('        1 : ' + tr('Trial division'))
        print('        2 : ' + tr('Wheel factorization'))
        print('        3 : ' + tr("Fermat's factorization"))
        print('        4 : ' + tr("Pollard's rho"))
        print('        5 : ' + 'p - 1')

        if cracker: color(c_succes)
        print('    ' + '-' * 16)
        if cracker: color(c_wrdlt)

        print('    ' + tr("Probabilistic primality's test"))
        if cracker: color(c_ascii)
        print('        6 : ' + tr("Fermat's test"))
        print('        7 : ' + tr("Miller-Rabin's test"))

        if cracker: color(c_succes)
        print('    ' + '-' * 16)
        if cracker: color(c_wrdlt)

        print('    ' + tr('Sieves to find prime numbers'))
        if cracker: color(c_ascii)
        print('        8 : ' + tr('Sieve of Erathostenes'))
        print('        9 : ' + tr('Segmented sieve of Erathostenes'))

        c = ''
        if cracker: c = cl_inp('\n' + tr('Your choice : '))
        else: c = input('\n' + tr('Your choice : '))

        if c not in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'q'):
            prnt = '"' + c + '" ' + tr('is NOT an option of this menu !')
            if cracker: cl_out(c_error, prnt)
            else: print(prnt)

        if c in ('1', '2', '3', '4', '5', '6', '7'):
            if cracker: n = inp_int(tr('Enter the integer number : '))
            else: n = int(input(tr('Enter the integer number : ')))

        if c != '0':

            t1 = datetime.now()

            dct = {
                '1': tr('Trial division'),
                '2': tr('Wheel factorization'),
                '3': tr("Fermat's factorization"),
                '4': tr("Pollard's rho"),
                '5': 'p - 1',
                '6': tr("Miller-Rabin's test"),
                '7': tr("Fermat's test"),
                '8': tr('Sieve of Erathostenes'),
                '9': tr('Segmented sieve of Erathostenes')
            }

            t1 = datetime.now()

            if c == '7':
                if cracker:
                    nt = inp_int(
                        tr('Number of tests (Error = 0.25 ^ number of tests) : '
                           ))
                else:
                    nt = int(
                        input(
                            tr('Number of tests (Error = 0.25 ^ number of tests) : '
                               )))
                txt = to_str(dct['7'], n, nt)
            else:

                if c in ('8', '9'):
                    if cracker: n = inp_int(tr('Limit : '))
                    else: n = int(input(tr('Limit : ')))
                    if c == '8':
                        f = basic_erathostenes_sieve
                    else:
                        f = segmentation_erathostenes_sieve
                    L = f(n)
                    txt = ""
                else:
                    txt = to_str(dct[c], n)

            t = datetime.now() - t1

            print(txt)

            if c in ('1', '2', '3', '4', '5', '6', '7', '8', '9'):
                if cracker: cl_out(c_succes, tr('Realised in ') + str(t))
                else: print(tr('Realised in ') + str(t))

                if c in ('8', '9'):
                    print(tr('Length of the list :'), len(L))
                    ans = input(tr('Write the prime numbers in a file ? '))
                    if ans in (tr('y'), tr('Y'), tr('yes'), tr('Yes'),
                               tr('YES')):
                        nf = input(
                            tr('Name of the file (a file of the same name will be erase) : '
                               ))
                        f = open(nf, 'w')
                        for k in L:
                            f.write(str(k) + "\n")
                        f.close()
                    else:
                        if len(L) < 1000:
                            ans = input(tr('Print the list on the screen ? '))
                            if ans in (tr('y'), tr('Y'), tr('yes'), tr('Yes'),
                                       tr('YES')):
                                for k in L:
                                    print(k)
                if cracker: color(c_wrdlt)
                input(tr('---End---'))
                if cracker: color(c_prog)