Exemple #1
0
def signature(inputfile, mode_signature, key='1'):
    inputfile = fileio.readfile(inputfile)
    if mode_signature == 'elgamal':
        signature = signature_elgamal.Sign_elgamal(512, key)
        rr, ss = signature.sign(inputfile)
        fileio.writefile('rr_signed', rr.to_bytes(128, byteorder='big'))
        fileio.writefile('ss_signed', ss.to_bytes(128, byteorder='big'))
    else:
        signature = signature_RSA.Sign_hash(key)
        signed = signature.sign(inputfile)
        fileio.writefile('rsa_signed', signed.to_bytes(128, byteorder='big'))
    return signature
Exemple #2
0
def dechifKasumi(inputfile,
                 outputfile,
                 mode,
                 key=0x9900aabbccddeeff1122334455667788,
                 iv=0x121a12340987198):
    inputfile = fileio.readfile(inputfile)
    kasumsym = Kasumi.Kasumi_symtrique(key)
    if mode == 'ecb':
        msg_dec = kasumsym.decryption_ecb(inputfile)
    elif mode == 'cbc':
        msg_dec = kasumsym.decryption_cbc(inputfile, iv)
    elif mode == 'pcbc':
        msg_dec = kasumsym.decryption_pcbc(inputfile, iv)
    else:
        msg_dec = kasumsym.decryption_ecb(inputfile)
    print(inputfile)
    print(msg_dec)
    fileio.writefile(outputfile, msg_dec)
    return msg_dec
Exemple #3
0
            name = input('/>')
            print("Enter number of bits:")
            nbits = int(input('/>'))
            print("Enter number Confidence:")
            confidence = int(input('/>'))
            key_generate.create_keypair(nbits, confidence, name)
            print(
                'Generation de cle fini. Trouve ces valeurs dans le fichier key/elgamal/name_key'
            )
        elif selection == '4':
            print("Generation de hashage sans signature avec Modified MD5\n")
            print("Enter file directory to read from")
            inputfile = input('/>')
            print("Enter file directory to write to")
            outputfile = input('/>')
            inputfile = fileio.readfile(inputfile)
            hashsponge = eponge_md5.hash_sponge(inputfile)
            print('Hashage generation finished')
            fileio.writefile(outputfile,
                             hashsponge.to_bytes(16, byteorder='big'))
        elif selection == '5':
            print(
                "Signature avec cle pair en mode RSA ou Elgamal: First select your mode"
            )
            mode_signature = input('/>')
            print("Enter file directory to read from")
            inputfile = input('/>')

            print("Enter the name of key pair to use")
            name_key = input('/>')
            if mode_signature == 'elgamal':
            blockdecry = blockdecry ^ previous_cipher ^ previous_plain
            previous_cipher = block
            previous_plain = blockdecry
            print("block:", hex(block),
                  "previous_cipher:", hex(previous_cipher), "previous_plain",
                  hex(previous_plain), "encryption:", hex(blockdecry))
            blockbyte = blockdecry.to_bytes(8, byteorder="little")
            blocks_dec.append(blockbyte)
            # CBC mode decrypt: previous XOR decrypt(ciphertext)
            #for each block we do: 1.decryption KASUMI 2. Add vector previous
        return self.unpad(b''.join(blocks_dec))

if __name__ == '__main__':
    key = 0x9900aabbccddeeff1122334455667788
    msg = "hillooverby2_fuckgs15"
    arr = bytes(msg, 'utf-8')
    kasumsym = Kasumi_symtrique(key)
    iv = 0x121a12340987198
    #msg_enc = kasumsym.encryption_ecb(arr)
    #msg_dec = kasumsym.decryption_ecb(msg_enc)
    #msg_enc = kasumsym.encryption_cbc(arr,iv)
    #msg_dec = kasumsym.decryption_cbc(msg_enc,iv)
    arr = fileio.readfile('data.txt')
    msg_enc = kasumsym.encryption_pcbc(arr, iv)
    fileio.writefile('enc', msg_enc)
    msg_dec = fileio.readfile('enc')
    msg_dec = kasumsym.decryption_pcbc(msg_enc, iv)
    fileio.writefile('dec', msg_dec)
    print(arr)
    print(msg_enc)
    print(msg_dec)