user12693314
user12693314

Reputation:

Why python don't write anything into a dictionary?

I'm creating a program that saves his infos as encoded infos using a method that I created.

Basically when I start the program it creates two variables,

That's the "key" to a "key" I give it a random number using random.randint(1000000000,9999999999) and this number I call it the name of the "key".

All the keys and theirs name are stored in a file.

In the program you have the opportunity to write something like a name, that name is going to be encrypted using the key that is generated when I start the program, then stored in a file along with the name of the key.

(Note that the keys always have a different name, the encrypted data may has been encrypted using many times the same key then stored in another file).

I read from the key file first

{NOTE: the keys are stored using a \n pattern, example file.write(f'{key}\n{key_name}\n') }

using my method the length will always be divisible for 2 so I use a variable initialized before the for cycle and increase it along with the cycle, meanwhile I use that same variable to read from the list (the result of reading the key file) and assign a name to a key, example:

{4819572: 'varoabIfokdbKjs3918', 40101846: 'opqihduqv', 8291073: 'hqowirhwip', ...} 

My keys are 354 chars long so those are a really small example.

Here is the code described above

sep = os.sep
Ot = platform.system()
file_name = os.path.basename(__file__)
path_to_file = __file__.replace(file_name, '')

with open(f'{path_to_file}database{sep}history.dll', 'r', encoding='utf-8') as file:
    keys = file.readlines()

num = 0
archive = {}
for _ in range(int(len(keys)/2)):
    key_name = str(keys[num+1]).replace('\n','')
    key = str(keys[num]).replace('\n','')
    archive[int(key_name)] = key
    num =+ 2
num1 = 0
num2 = 0

After this I use the key_name to get the key which is used in a decrypt function along with the encrypted text.

The problem is that even if I have 16 keys in the dictionary there are only 2. I really don't know how to resolve this or why this is appending.

Upvotes: 0

Views: 77

Answers (1)

Inlife and you too.
Inlife and you too.

Reputation: 36

You have writen "num =+ 2", I think you wanted write "num += 2"

Upvotes: 1

Related Questions