May-08-2017, 12:07 AM
So below is my Python code. I'm just messing around with what I was going to use as base for a new project. But after only 2 minutes of writing, I hit a wall. I've been trying various methods to fix it, but I have failed so far unfortunately. Any help at all would be appreciated. The program itself is meant to store the results and then let those be accessed afterwards. In other words, the first things printed should match the second things printed.
It should be easy to understand once you run the code I'm sure, as for the problem, maybe not so. I added extra comments to the code, although it is not my usual practice. Equally, variable names are somewhat poor as I just want to make things work properly first. I've been programming in more languages than I can count for over 8 years now. But I suppose my Python must be rusty.
picpaste. com/pics/1sBgcjGJ.1494201640.png - It wouldn't like me post an image link with my first post, so I've spaced out the URL.
It should be easy to understand once you run the code I'm sure, as for the problem, maybe not so. I added extra comments to the code, although it is not my usual practice. Equally, variable names are somewhat poor as I just want to make things work properly first. I've been programming in more languages than I can count for over 8 years now. But I suppose my Python must be rusty.
# Imports from pprint import pprint data = [] results = [] # XOR each piece of data based on the value of 'x' def xorEncrypt(data, x): for i in range(0, len(data)): data[i] = data[i] ^ x return data # Fill up the data list with 0 to 15 - 16 entres in total # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] for x in range(0, 16): data.append(x) # XOR 'encrypt' using the value of 'i' and add the results to a list (called # 'results'). Plus, print the result with each iteration. for i in range(0, 10): result = xorEncrypt(data, i) print("Result:", result) results.append(result) # Break-line and heading print("------------------------------------------------------------------") print("Final reuslts:") # Pretty print the results pprint(results)A photo of the output on my machine. A friend also got the same result using a brand new installation of Python on a fresh machine.
picpaste. com/pics/1sBgcjGJ.1494201640.png - It wouldn't like me post an image link with my first post, so I've spaced out the URL.