farmwife 0 Light Poster

Okay, so cryptography is insanely well developed and I'm not doing anything new here, but I still thought I'd monkey around with a cryptography project. Here's what I want it to do:

1) generate an encryption and decryption key that is randomly between 20 and 40 digits long and contains random, single decimal digits.
2) encrypt a file character by character as follows:
a) randomly choose one of its decimal digits
b) multiply the ascii value of an input character by that randomly chosen digit
c) index the location of the randomly chosen digit within the encryption key
3) decrypt the same file as follows:
a) request input of the entire numeric key
b)reference the appended digits to determine which of the pre-append digits was used to encrypt the specific input character
c) divide the encrypted character's numeric value by the value of the pre-append digit to obtain its ascii value, then convert it to an ascii character

Generating the key is stupidly easy:

import random

def key_gen():
    key = 0
    key_length = random.randint(20,40)
    for i in range(key_length):
        key = key * 10 + random.randint(0,9)
    return key

But the encryption is trickier:

import random

def encrypt_inputs(key, inputs):
    final_key, orig_length, outputs = str(key) + '.', len(final_key) ''
    for i in range(len(key_string)):
        a = random.randint(0, orig_length // 10)
        b = random.randint(0, orig_length % 10)
        outputs = outputs + str(asc(inputs[a]) * key(a*10+b))
        final_key = final_key + str(a) + str(b)
    return int(final_key), outputs  

And the decryption? The whole thing makes my head hurt.

I hope some encryption enthusiast enjoy discussing this. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.