Basic Scramble Code

I spent some time the past few days playing about with the idea of making a bit of code that takes an input string of readable text and outputs a scrambled string that is unreadable.

Scrambler.py seemed a fitting name for this useless little predictable function.
Only 3 functions make up the program; Key, Scramble and Read.
Key is a function that when called simply allows you to set the key by which the text is scrambled, instead of letting the program give you a random key.
Well this was left in from when i was setting the key manually, I don’t think it’ll work now as when the scramble function is called, it’s randomises the key int.
Scramble is the main function, it takes the input string and reads each letter in with a for loop , this then takes the letter and finds the int value of that letter, it them subtracts the value of the key int form the letter value, converts that value back into a chr and concatenates it to the Scramble string.
After all that, it returns the key number with print, checks if you want to show the string or not (this is useful for large strings and text bodies) and ends the program.
The Scrambled text is then usable by printing the string attached to “Scramble”.
The read function is the last bit of code in the program.
This function takes the input string and the value of the key, runs the scramble function in reverse and saves the string to “clean”.
Its important that you have the key value, otherwise it will not be able to find the correct chr value again to make the text readable.

I’m not going to bother giving you the source for this program as it is so small and useless, it’s been more of a thought experiment for me.