import binascii

def xorKey(secret):
    secret = secret.encode()
    hexstr = binascii.hexlify(secret)
    key = int(hexstr, 16)
    print("Klucz: ", key)
    return key

def xorEnc(msg, key):
    msg = msg.encode()
    hexstr = binascii.hexlify(msg)
    print("Postać szesnastkowa: ", hexstr)
    ciphertext = int(hexstr, 16) ^ key
    print("Szyfrogram: ", ciphertext)
    return ciphertext

def xorDec(msg, key):
    xorMsgKey = msg ^ key
    back2hex = format(xorMsgKey, 'x')
    print("Ponownie wartość szesnastkowa: ", back2hex)
    evenpad = ('0' * (len(back2hex) % 2)) + back2hex
    plaintext = binascii.unhexlify(evenpad)
    print("Tekst w jawnej postaci: ", plaintext)
    return plaintext

key = xorKey("tajemnica")
key2 = xorKey("zleHaslo")
cipher = xorEnc('Witaj',key)
plain = xorDec(cipher,key)
wrongplain = xorDec(cipher, key2)
