def find_key7(ct):
    first4 = ct[:4]
    first4 = conversions.xor(first4, 'FROM')
    text = ct[:20]
    max_score = 0
    max_score_key = ''
    max_score_i = 0
    rating = 0
    for i in range(2**16):
        javarandom.state = ogState * (2**16) + i
        keystream = first4 + javarandom.get_bytes(30)
        a = keystream[:20]
        rating = (1 * count_printable(conversions.xor(text, a))) + (
            .75 * count_letters(conversions.xor(text, a))) + (englishy(
                conversions.xor(text, a)))
        if rating >= max_score:
            max_score_i = i
            max_score = rating
            max_score_key = keystream
    s = bin(max_score_i)
    s = make16(s)
    b = splita16(s)
    c = splitb16(s)
    bit16 = chr(int(b, 2)) + chr(int(c, 2))
    fin = conversions.as_to_hex(bit16)
    return fin
Exemple #2
0
def r3(hashval, col):
    passwordspace = b26_to_num('zzzz')
    hashsmall = (b64_to_bits(hashval[:8]))
    result = conversions.xor(num_to_b26(hashsmall, 4), num_to_b26(col, 4))
    result = conversions.as_to_b64(result)
    result = b64_to_bits(result) % passwordspace
    return num_to_b26(result, 4)
def repeating_byte_xor(text, key):
    a = len(text)
    b = len(key)
    c = (a / b)
    d = mod(a, b)
    new_key = (key * c) + key[:d]
    f = conversions.xor(text, new_key)
    return f
Exemple #4
0
def galois(x, y):
    z = ''
    for i in range(128):
        z += str('0')
    v = x
    r = "11100001"
    for i in range(120):
        r += str('0')
    for j in range(127):
        if (y[j] == "1"):
            z = ''.join(map(str, conversions.as_to_lis(conversions.xor(z, v))))
        if (v[127] == "0"):
            v = rightshift(v)
        else:
            v = ''.join(
                map(str,
                    conversions.as_to_lis(conversions.xor(rightshift(v), r))))
    return z
def return_key7(ct):
    first4 = ct[:4]
    first4 = conversions.xor(first4, 'FROM')
    text = ct[:20]
    max_score = 0
    max_score_key = ''
    max_score_i = 0
    rating = 0
    for i in range(14814, 14815):
        javarandom.state = ogState * (2**16) + i
        keystream = first4 + javarandom.get_bytes(len(ct))
        a = keystream[:len(ct)]
        rating = (1 * count_printable(conversions.xor(text, a))) + (
            .75 * count_letters(conversions.xor(text, a))) + (englishy(
                conversions.xor(text, a)))
        if rating >= max_score:
            max_score_i = i
            max_score = rating
            max_score_key = keystream
    return max_score_key
Exemple #6
0
def r2(hashval, colindex):
    param3 = colindex
    passwordspace = b26_to_num('zzzz')
    hash_as_bits = b64_to_bits(hashval[:8])
    result = (hash_as_bits * param3 + colindex) % passwordspace
    # result = (kthroot(hash_as_bits, colindex) + colindex * param3)**2 % passwordspace
    arg1 = result % passwordspace
    arg2 = (hash_as_bits - colindex) % passwordspace
    # print arg1, arg2
    result2 = conversions.xor(num_to_b26(arg1, 4), num_to_b26(arg2, 4))
    result3 = b64_to_bits(conversions.as_to_b64(result2)) % passwordspace
    return num_to_b26(result3, 4)
Exemple #7
0
def last_nonpad_byte(ciphertext):
    empty = '0000000000000000'
    wrong = '<html'  #gives wrong padding
    if (len(ciphertext) > 48):
        start = 32
        end = 48
        c1 = ciphertext[start:end]
    else:
        start = 16
        end = 32
        c1 = ciphertext[start:end]
    as_c1 = conversions.hex_to_as(c1)
    length = pad_length(ciphertext)
    xor_c1 = conversions.xor(chr(length), chr(length + 1))
    hex_xor_c1 = conversions.as_to_hex(xor_c1)
    xor_c1_final = empty[:-(length * 2)] + (hex_xor_c1 * length)
    as_xor_c1 = conversions.hex_to_as(xor_c1_final)
    c2 = conversions.xor(as_c1, as_xor_c1)
    hex_c2 = conversions.as_to_hex(c2)
    oracle = webserver_msgs.post_dictionary_guess(
        '', (ciphertext[:start] + hex_c2 + ciphertext[end:]))
    if (oracle == wrong):
        last_byte = conversions.as_to_hex(chr(length + 1))
    else:
        for i in range(255):
            test_byte = conversions.as_to_hex(chr(i))
            test_byte_as = chr(i)
            xor_c1 = empty[:-(
                (length + 1) * 2)] + test_byte + (hex_xor_c1 * length)
            as_xor_c1 = conversions.hex_to_as(xor_c1)
            c2 = conversions.xor(as_c1, as_xor_c1)
            hex_c2 = conversions.as_to_hex(c2)
            oracle = webserver_msgs.post_dictionary_guess(
                '', (ciphertext[:start] + hex_c2 + ciphertext[end:]))
            oracle = oracle[0:5]
            if (oracle == wrong):
                last = conversions.xor(test_byte_as, chr(length + 1))
                last = conversions.as_to_hex(last)
    return last
def encdec(key, message):
    init_state(key)
    keystream = get_bytes(len(message))
    return conversions.xor(keystream, message)
    return max_score_key


##key6b = '1485553999'

## 7

cipher7_b64 = "+TlPSjTjDtFLO8bItE0qLB8oK4Sy1YT1KEkrEitEGH+5gnL/TEePLjHyv2evx3LYivXLt8c9z0FtMj/ESl1/NrYXsoe/lb2QJJnAzLVlwyYgGIx9BLaUCqmT3JO5raBwxTNNN5uGzc+vqXIIp+fP/hIk8lWlUx6JCQ2sKQe56A9ZKurAB1hY/BcaO7umXwT6hJ2b0/kv+FCJHtaQX0yWEQ/IVsG/bqJe5U4zv0ZsYaZEBHAKpicQztFSM4XlgBwsWFdNGLsM29r4q73XYWmP7jHMf0jdkDgA/5gn3kcHKo7n16bffrP1y59dHMDrPVWm+5J6K6z2nTkwsYXE+xUuXONRE2oZ77yypw5uR8VzoOZvxOJKkXjaL0KY72SsMdqL65tsQG33QF94N/n+yBdnV4Ccg/6Hbzvg/3hX5UyrMIhARfSSpOQLzzjCQhwdN5sFSkZGs7s9NX9gWGw9zqGvc5JIgz7eHHpKZsgEl89QuMCw3c+ZYTYKJzB3xUf79W6HeSyc66DxLLTNls3f+TkiteXObY2uLCrBlfDucNP+iaVqSa4DlBDVFlaI9ByZ//hYx6njzbIsHjcoZmMZnduI9hHQZrUFex0Oj/V/g8FaoEP/quGVoh6uQ2CsF/cmh98afM792w744LbhcVj/N1TXdRXlP+yzaePBEEVJQlErU9KoORk/DNe6d08xzigJfJZVzElpvjJwpCCZj9DVCL0yTyUCePKGNRADYAB8jAK3cNnUQnoSvM0+ZzBqRRn0TxNpY96BjSlidgzHFkxPCHIfdTjWsP3Qd7PSJEisTg3WyH3vlZWw1ZnthJrN7NVuY+S5N6zrPvdtWA5qk1SIU3pi74IW8Out3XD+KiCC1Pt3GfG11cdTSx5aRt9Oynjd8ZmOu4ADzEroHeLVKveZNEvAfGLZLubu0jbqxq9vfJkMyRmgQ8OsS6AiHGI8Tk+1aiBIPwoyJ4lCactb/WS2gakI5655Nw1oqp2y/q4Quy1zRPZ2ilephQALRsr2YzebLHounOW3JKPn5d6s0CeoCPwO2V9NczIBG7U+ww=="
cipher7 = conversions.b64_to_as(cipher7_b64)


def binary(num, pre='', length=8, spacer=0):
    return '{0}{{:{1}>{2}}}'.format(pre, spacer, length).format(bin(num)[2:])


theXOR = conversions.as_to_lis(conversions.xor('FROM', cipher7[:4]))
binXOR = bin(191) + binary(107) + binary(0) + binary(7)
ogState = long(binXOR, 2)


def make16(s):
    s = s[2:]
    while len(s) < 16:
        s = '0' + s
    s = '0b' + s
    return s


def splita16(s):
    return s[:10]
def individual_xor(ct, k):
    plain = conversions.xor(ct, k * len(ct))
    return plain
def new_xor(text, key):
    plain = conversions.xor(text, key)
    return plain
Exemple #12
0
def rc4(key, text):
    initstate = rc4_initialize(key)
    keystream = rc4_genbytes(initstate, len(text))
    return conversions.xor(keystream, text)