Hello.
Imagin we have a python file with many alphabet letters like this: (Which is infact meaningful like i am a programmer)

i
a
m
a
p
r
o
g
r
a
m
m
e
r

How can i print them randomly that nobody could read it? sth like this for example:

g
a
i
m
r
a
m
r
p
r
a
o
e
m

And i want the program when i enter the password, print the exact primary model which we had first.

Please try to guide me first, friends. I dont't want the main answer now because i'm trying to learn and want to try and get the correct result myself, i just need your guidness first.
If i couldn't get the correct result, i will ask you to help me with anser finally.
Thank you so much :)

The random module may be helpful.

Here is a big hint.

>>> import random
>>> s = 'i am a programmer'
>>> ''.join(random.sample(s, len(s)))
'm mraep mriago ra'
>>> #no whitespace
>>> s_1 = ''.join(s.split())
>>> ''.join(random.sample(s_1, len(s_1)))
'omagripramamer'

Pretty much what Lardmeister said however, if you want a strong encryption you shouldn't try to implement an encrypting algorithm yourself but use an already existing and known implementation. If it's for a test purpose, you can try and implement the Ceaser cipher your self, it is one of the most basics one

Just to play with random stuff:

import random
# mix of upper/lower case
for k in range(26):
    random_integer = random.randint(65, 90)
    c = chr(random_integer)
    if random.randint(0, 1):
        print(c.lower())
    else:
        print(c)

print('='*10)

# characters will not repeat
for m in random.sample(range(65, 91), 26):
    print(chr(m))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.