Esempio n. 1
0
File: des.py Progetto: AmesianX/des
def bits_to_pretty(bits, blocksize=8):
    return "%s (0x%s)" % \
        (bittools.bits_to_binary_string(bits, blocksize), bittools.bits_to_hex(bits))
    '''
    return "0x%s %s-bit" % \
        (bittools.bits_to_hex(bits), len(bits))
    '''
    '''
Esempio n. 2
0
File: des.py Progetto: wegam/des-1
def bits_to_pretty(bits, blocksize=8):
    return "%s (0x%s)" % \
        (bittools.bits_to_binary_string(bits, blocksize), bittools.bits_to_hex(bits))
    '''
    return "0x%s %s-bit" % \
        (bittools.bits_to_hex(bits), len(bits))
    '''
    '''
Esempio n. 3
0
def zip_and_format(bits):
    result = ""

    zipped = zip(*(bits for i in xrange(64)))

    width = 4
    for i, item in enumerate(zipped):
        if i % width == 0:
            result += "    "
        result += "0x%sLL" % bittools.bits_to_hex(item)
        if i != 63:
            result += ","
        if i % width == width - 1:
            result += "\n"
        else:
            result += " "

    return result
Esempio n. 4
0
def zip_and_format(bits):
    result = ""

    zipped = zip(*(bits for i in xrange(64)))

    width = 4
    for i, item in enumerate(zipped):
        if i%width == 0:
            result += "    "
        result += "0x%sLL" % bittools.bits_to_hex(item)
        if i != 63:
            result += ","
        if i%width == width-1:
            result += "\n"
        else:
            result += " "

    return result
Esempio n. 5
0
File: des.py Progetto: wegam/des-1
            decrypt = options.decrypt
        else:
            # 3DES is EDE / DED, so round 2 is opposite.
            decrypt = not options.decrypt

        result = []
        for t in text:
            if decrypt:
                result += dsa_decrypt(t, key)
            else:
                result += dsa_encrypt(t, key)

        if options.file:
            filename = options.file + '.' + str(round) + '.'
            if decrypt:
                filename += 'decrypted'
            else:
                filename += 'encrypted'
            with open(filename, "wb") as f:
                f.write(bittools.bits_to_ascii(result))

        # Subsequent rounds are based on the result.
        text = []
        for i in range(0, len(result), 64):
            text.append(result[i:i + 64])

    if options.ascii and decrypt:
        print bittools.bits_to_ascii(result)
    else:
        print bittools.bits_to_hex(result)
Esempio n. 6
0
import sys
import os.path

# Add lib/ to sys.path
lib_directory = os.path.realpath(os.path.join(__file__, "../../lib/"))
sys.path.append(lib_directory)

import bittools

if __name__ == "__main__":

    key = bittools.hex_to_bits(sys.argv[1])
    #for i in [63, 55, 47, 39, 31, 23, 15, 7]:
    for i in [7, 15, 23, 31, 39, 47, 55, 63]:
        key.insert(i, 0)
    print bittools.bits_to_hex(key)
Esempio n. 7
0
File: des.py Progetto: AmesianX/des
    key = bittools.hex_to_bits(args[1])

    # text is plaintext if encrypting or ciphertext if decrypting
    if options.ascii and not options.decrypt:
        text = bittools.ascii_to_bits(args[0])
    else:
        text = bittools.hex_to_bits(args[0])
    if len(text) != 64:
        if options.decrypt:
            op.error("ciphertext must be 16 hex digits")
        else:
            op.error("plaintext must be 16 hex digits (or 8 ascii letters if using -a/--ascii)")
    if len(key) != 64:
        print key, len(key)
        op.error("key must be 16 hex digits")

    if options.verbose:
        print_logs = True
    else:
        print_logs = False

    if options.decrypt:
        result = dsa_decrypt(text, key)
    else:
        result = dsa_encrypt(text, key)

    if options.ascii and options.decrypt:
        print bittools.bits_to_ascii(result)
    else:
        print bittools.bits_to_hex(result)