Generating a Cryptographic Key Using Fibonacci Sequence in Python

I'm trying to generate a cryptographic key using the Fibonacci sequence in Python. I have a specific key (ebe42a225e8593e448d9c5457381aaf7) that I want to use as a starting point. However, my current implementation is not working as expected. Could someone please help me identify the issue in my code and provide guidance on how to achieve this?

def generate_key_from_fibonacci(seed_key):
    # Convert the seed key from hexadecimal to an integer
    seed_key_int = int(seed_key, 16)

    # Generate Fibonacci numbers until the key length is reached
    fib_nums = [0, 1]
    while len(fib_nums[-1]) < len(seed_key):
        next_fib = fib_nums[-1] + fib_nums[-2]
        fib_nums.append(next_fib)

    # Truncate or expand the last Fibonacci number to match the key length
    fib_nums[-1] = fib_nums[-1][:len(seed_key)]

    # XOR each Fibonacci number with the seed key
    key = hex(int(seed_key, 16) ^ int(fib_nums[-1], 2))[2:]

    return key

seed_key = 'ebe42a225e8593e448d9c5457381aaf7'
generated_key = generate_key_from_fibonacci(seed_key)
print("Generated Key:", generated_key)

I would greatly appreciate any assistance or suggestions on how to modify my code to generate a cryptographic key using the Fibonacci sequence in Python. Thank you in advance.

Thank you for helping me.

1
Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article