r/pythonhelp • u/tomsumner77 • Aug 03 '22
encoding and decoding in python
I'm working on an encoder and decoder. my encoder works well however I can't seem to figure out how to make the decoder work. My encoder works by finding each letter's number in the alphabet. EG a = 1, b =2 and then times that number by a random number which is generated using a random.random() and a random.seed(my numbers), it then gets the last number of this float and uses it to get a letter from the dict.
Can anyone help me figure out how to get the decoder to work, if any more code or description is required please let me know?
3
Upvotes
2
u/Zeroflops Aug 04 '22
You just reverse the process by generating a random number, dividing your encoded digit and converting back to letters.
The point of the assignment is to show you that random numbers are not random. And by using a seed you can recreate a random sequence.
Set a random seed to something simple like 5. Then create three random numbers. Then reset the random seed to 5, and create 3 more random numbers.
There are ways of making it more random like, for example set the seed by the number of second in the day when the program runs. But computers can’t generate pure random numbers
Which is why they use other means to generate random numbers.
https://www.thesized.com/cloudflare-lava-lamps-randomness/
BTW. Having a random number generator that isn’t only sudo random can be a useful thing. The numbers it generates are based on old random tables meaning number to number the values have random characteristics. So they can be used when random numbers are needed. But at the same time research can be repeatable by supplying a seed when doing random calculation.
So a good research paper that needs randomness will run calculations on a number of different seeds. But then the data that is presented in the paper will be presented with the seed used to create it so ppl can audit the research.