lundi 25 septembre 2023

Encryption With Randomization Decryptor

A friend of mine wanted to create encryption using randomization, and I told him that was a bad idea. I wanted to create a file to prove him wrong, however, I noticed that the product that I came up with wasn't always accurate. For example:

I would input hello, and the algorithm would output:

hcllo

My program multiplies the order of the characters by a random number (1-10000) and then runs it through to see which random number works to get a simple ascii character. I have no idea why it is working.

My code:

import random
import time
def PairValueKey(key):
    end = ''
    for x in range(len(key)):
        val = ord(key[x])
        val = int(val) * random.randint(0,10000)
        end = str(end) + '\\' + str(val)
    end = end + '\\'
    return(end)

def FindInput(key):
    sec = ''
    inpu = ''
    for x in range(len(key)):
        if key[x] == '\\':
            if not sec == '':
                for y in range(10000):
                    if y > 0:
                        trynum = int(sec) / int(y)
                        trynum = str(trynum).replace('.0', '')
                        tmp = list(trynum)
                        if not '.' in tmp:
                            if int(trynum) > 122:
                                pass
                            else:
                                inpu = inpu + str(chr(int(trynum)))
                                sec = ''
                                break
        else:
            sec = sec + str(key[x])
    return inpu
                        
            

print('''
       * * * * * * * * * * * * * * * * *
      *  Why random numbers should NOT  *
      *    be used for cryptography     *
       * * * * * * * * * * * * * * * * *
      ''')
print('''Enter a password. This password will then be paired
to a set of random numbers (1-10000), and then will be
decrypted by the software after.
      
Keep in mind that the decryption software isn't accurate,
but it can still retrieve some of your password,
which could be fed into a data collection service afterwards.
      ''')

key = PairValueKey(input("Password: "))
print('This is your unique key containing your password:')
print(key)
time.sleep(2)
print('Seems secure, right?')
time.sleep(2)
print('Think again.')
time.sleep(2)
print('Calculating...\n')
inpu = FindInput(key)
print('The algorithm calculated: ')
print(inpu)



Aucun commentaire:

Enregistrer un commentaire