def test(itt):
    for i in range(itt):
        size_src = random.randint(-10000, 10000)
        size_key = random.randint(-10000, 10000)
        st = random.randint(-10000, 10000)
        le = random.randint(-10000, 10000)
        try:
            src = rnd.get_rnd(size_src)
            key = rnd.get_rnd(size_key)

            h0 = ncp.hash_r(src, 16)

            ncp.encoder_bits(src, key, st, le)
            ncp.decoder_bits(src, key, st, le)

            h1 = ncp.hash_r(src, 16)
            if h0 == h1:
                print('[%4d] %8d %8d %8d %8d - test bits - ok' %
                      (i, size_src, size_key, st, le))
            else:
                print('[%4d] %8d %8d %8d %8d - test bits - hash !=' %
                      (i, size_src, size_key, st, le))
                return (1)
        except:
            print('[%4d] %8d %8d %8d %8d - test bits -error' %
                  (i, size_src, size_key, st, le))
            return (1)
    return (0)
def test(itt):
    for i in range(itt):
        size_src = random.randint(-10000, 10000)
        st = random.randint(-10000, 10000)
        le = random.randint(-10000, 10000)
        sh = random.randint(-10000, 10000)
        sh_inv = 0 - sh
        try:
            src = rnd.get_rnd(size_src)

            h0 = ncp.hash_r(src, 16)

            ncp.shift(src, st, le, sh)
            ncp.shift(src, st, le, sh_inv)

            h1 = ncp.hash_r(src, 16)
            if h0 == h1:
                print('[%4d] %8d %8d %8d %8d - test shift - ok' %
                      (i, size_src, st, le, sh))
            else:
                print('[%4d] %8d %8d %8d %8d - test shift - hash !=' %
                      (i, size_src, st, le, sh))
                return (1)
        except:
            print('[%4d] %8d %8d %8d %8d - test shift - error' %
                  (i, size_src, st, le, sh))
            return (1)
    return (0)
def test(itt):
    for i in range(itt):
        size_src = random.randint(-10000, 10000)
        st = random.randint(-10000, 10000)
        le = random.randint(-10000, 10000)
        try:
            src = rnd.get_rnd(size_src)

            h0 = ncp.hash_r(src, 16)

            ncp.reverse(src, st, le)
            ncp.reverse(src, st, le)

            h1 = ncp.hash_r(src, 16)
            if h0 == h1:
                print('[%4d] %8d %8d %8d - test reverse - ok' %
                      (i, size_src, st, le))
            else:
                print('[%4d] %8d %8d %8d - test reverse - hash !=' %
                      (i, size_src, st, le))
                return (1)
        except:
            print('[%4d] %8d %8d %8d - test reverse - error' %
                  (i, size_src, st, le))
            return (1)
    return (0)
Exemple #4
0
#!/usr/bin/env python3

import prn
import rnd

# ---------------------------------------------------------------------------- #
a = rnd.get_rnd(32)
prn.print_bytes(a, 24)

# ---------------------------------------------------------------------------- #
a = rnd.get_rnd(1343)
prn.print_bytes(a, 16)

# ---------------------------------------------------------------------------- #
a = rnd.get_rnd(332)
prn.print_bytes(a, 8)

# ---------------------------------------------------------------------------- #
a = rnd.get_rnd(1011)
prn.print_bytes(a, 1)

# ---------------------------------------------------------------------------- #
a = rnd.get_rnd(100)
prn.print_bytes(a, 2)

# ---------------------------------------------------------------------------- #
a = rnd.get_rnd(100)
prn.print_bytes(a, 25)

# ---------------------------------------------------------------------------- #
a = rnd.get_rnd(1023)
Exemple #5
0
# parse arguments
src = ''
st = 0
le = 0

try:
    src = sys.argv[1]
    src = src.encode('utf-8')
    st = int(sys.argv[2])
    le = int(sys.argv[3])
except:
    print('Usage: <string> <start> <len>')
    exit()

print('-' * 80)
print(src)

# ---------------------------------------------------------------------------- #

key = rnd.get_rnd(128)

ncp.encoder_bits(src, key, st, le)
prn.print_bytes(src, 16)

ncp.decoder_bits(src, key, st, le)
prn.print_bytes(src, 16)

usrc = src.decode('utf-8')
print('-' * 80)
print(usrc)