コード例 #1
0
ファイル: main.py プロジェクト: 5GenCrypto/obfuscation
def test_all(args, obfuscate):
    success = True
    if not os.path.isdir(args.test_all):
        print("%s '%s' is not a valid directory" % (errorstr, args.test_all))
        sys.exit(1)
    ext = '.circ'
    for circuit in os.listdir(args.test_all):
        path = os.path.join(args.test_all, circuit)
        if os.path.isfile(path) and path.endswith(ext):
            success &= test_file(path, obfuscate, args)
        if os.path.isfile(path) and path.endswith('.json'):
            success &= test_file(path, obfuscate, args, formula=False)
    return success
コード例 #2
0
ファイル: main.py プロジェクト: nickhakkz/obfuscation
def test_all(args, obfuscate):
    success = True
    if not os.path.isdir(args.test_all):
        print("%s '%s' is not a valid directory" % (errorstr, args.test_all))
        sys.exit(1)
    ext = '.circ'
    for circuit in os.listdir(args.test_all):
        path = os.path.join(args.test_all, circuit)
        if os.path.isfile(path) and path.endswith(ext):
            success &= test_file(path, obfuscate, args)
        if os.path.isfile(path) and path.endswith('.json'):
            success &= test_file(path, obfuscate, args, formula=False)
    return success
コード例 #3
0
ファイル: main.py プロジェクト: gavz/obfuscation
def obf(args):
    if args.mmap not in ('CLT', 'GGH', 'DUMMY'):
        print('--mmap must be either CLT, GGH, or DUMMY')
        sys.exit(1)
    success = True
    try:
        if args.test:
            formula = is_formula(args.test, args)
            success = test_file(args.test, True, args, formula=formula)
        elif args.test_all:
            success = test_all(args, True)
        else:
            directory = None
            if args.load_obf:
                directory = args.load_obf
            elif args.load:
                formula = is_formula(args.load, args)
                start = time.time()
                obf = SZObfuscator(args.mmap,
                                   base=args.base,
                                   verbose=args.verbose,
                                   nthreads=args.nthreads,
                                   ncores=args.ncores)
                directory = args.save if args.save \
                            else '%s.obf.%d' % (args.load, args.secparam)
                obf.obfuscate(args.load,
                              args.secparam,
                              directory,
                              kappa=args.kappa,
                              formula=formula,
                              randomization=(not args.no_randomization),
                              seed=args.seed)
                end = time.time()
                print('Obfuscation took: %f seconds' % (end - start))
            else:
                print('%s One of --load-obf, --load, or '
                      '--test must be used' % errorstr)
                sys.exit(1)

            if args.eval:
                assert directory
                obf = SZObfuscator(args.mmap,
                                   base=args.base,
                                   verbose=args.verbose,
                                   nthreads=args.nthreads,
                                   ncores=args.ncores)
                r = obf.evaluate(directory, args.eval)
                print('Output = %d' % r)
    except ParseException as e:
        print('%s %s' % (errorstr, e))
        sys.exit(1)
    return success
コード例 #4
0
ファイル: main.py プロジェクト: amaloz/obfuscation
def obf(args):
    if args.mmap not in ('CLT', 'GGH', 'DUMMY'):
        print('--mmap must be either CLT, GGH, or DUMMY')
        sys.exit(1)
    success = True
    try:
        if args.test:
            formula = is_formula(args.test, args)
            success = test_file(args.test, True, args, formula=formula)
        elif args.test_all:
            success = test_all(args, True)
        else:
            directory = None
            if args.load_obf:
                directory = args.load_obf
            elif args.load:
                formula = is_formula(args.load, args)
                start = time.time()
                obf = SZObfuscator(args.mmap, base=args.base,
                                   verbose=args.verbose, nthreads=args.nthreads,
                                   ncores=args.ncores)
                directory = args.save if args.save \
                            else '%s.obf.%d' % (args.load, args.secparam)
                obf.obfuscate(args.load, args.secparam, directory,
                              kappa=args.kappa, formula=formula,
                              randomization=(not args.no_randomization),
                              seed=args.seed)
                end = time.time()
                print('Obfuscation took: %f seconds' % (end - start))
            else:
                print('%s One of --load-obf, --load, or '
                      '--test must be used' % errorstr)
                sys.exit(1)

            if args.eval:
                assert directory
                obf = SZObfuscator(args.mmap, base=args.base,
                                   verbose=args.verbose, nthreads=args.nthreads,
                                   ncores=args.ncores)
                r = obf.evaluate(directory, args.eval)
                print('Output = %d' % r)
    except ParseException as e:
        print('%s %s' % (errorstr, e))
        sys.exit(1)
    return success
コード例 #5
0
ファイル: main.py プロジェクト: 5GenCrypto/obfuscation
def bp(args):
    success = True
    try:
        if args.test:
            success = test_file(args.test, False, args)
        elif args.test_all:
            success = test_all(args, False)
        elif args.load:
            formula = is_formula(args.load, args)
            bp = SZBranchingProgram(args.load, base=args.base,
                                    verbose=args.verbose, formula=formula)
            if args.print:
                print(bp)
            if args.eval:
                r = bp.evaluate(args.eval)
                print('Output = %d' % r)
    except ParseException as e:
        print('%s %s' % (errorstr, e))
        sys.exit(1)
    return success
コード例 #6
0
ファイル: main.py プロジェクト: nickhakkz/obfuscation
def bp(args):
    success = True
    try:
        if args.test:
            success = test_file(args.test, False, args)
        elif args.test_all:
            success = test_all(args, False)
        elif args.load:
            formula = is_formula(args.load, args)
            bp = SZBranchingProgram(args.load,
                                    base=args.base,
                                    verbose=args.verbose,
                                    formula=formula)
            if args.print:
                print(bp)
            if args.eval:
                r = bp.evaluate(args.eval)
                print('Output = %d' % r)
    except ParseException as e:
        print('%s %s' % (errorstr, e))
        sys.exit(1)
    return success