I'm trying to make my own encryption algorithm but I don't know how to split strings that have different lengths into a list. Here is my code:
import random from calculations import test_divisibility # This is a function that returns which numbers can divide evenly into the given number def encrypt(text): div_by = test_divisibility(len(text)) if div_by is None: # If length of string is a prime number, figure out an alternate way to encrypt the string. pass divisor = random.choice(div_by) original = "This is the string to be hashed into the untitled hashing algorithm." print(encrypt(original)) The function will pick a random number from the returned list and divide that number into the length of the message to encrypt. The result of that number should be the number of slices the string should have.
Take for example the string "This is the string to be encrypted into my custom-made algorithm". If you pass the string to the function you will find that the length of the string is divisible by 2, 4, and 8. Then the random function is supposed to choose one of those numbers and divide the length of the string by that number. The result will be the number of slices the string should have.
没有评论:
发表评论