Some help, encryption and password generator


I need some help! I don’t know why my code does not work. I have limited experience. Encryption, password generator.
Repl link:

code snippet

Can you provide us with a link to your repl?


Hey @antoniolopesuk welcome to the forums!

What language are you using? If you are using Python as your language try this:

import random
import string

def generate_password(length=8):
    characters = string.ascii_letters + string.digits + string.punctuation
    password = "".join(random.choice(characters) for _ in range(length))
    return password

def encrypt(message, key):
    encrypted_message = ""
    for char in message:
        encrypted_message += chr(ord(char) + key)
    return encrypted_message

def decrypt(encrypted_message, key):
    decrypted_message = ""
    for char in encrypted_message:
        decrypted_message += chr(ord(char) - key)
    return decrypted_message

# Example usage
password = generate_password(12)
print("Generated Password:", password)

message = "Hello, World!"
key = 5

encrypted_message = encrypt(message, key)
print("Encrypted Message:", encrypted_message)

decrypted_message = decrypt(encrypted_message, key)
print("Decrypted Message:", decrypted_message)

This code has several unique functions:

• generate_password(length): It produces a random password of the length specified by the parameter. It combines uppercase and lowercase letters, punctuation symbols, and digits to create a decently strong password.

• encrypt(message, key): Encrypts a string of text put in the message parameter by moving each character’s Unicode value by the key specified in the parameter. It then returns the encrypted text as a string.

• decrypt(encrypted_message, key): Decrypts an encrypted message by shifting each character’s Unicode value back by the key specified by the parameter. It then returns the decrypted text as a string.

In the example section, a password is made using the function generate_password() and is then printed out. A message is then encrypted using the function encrypt() with a key of 5, and then the encrypted message is printed out. The encrypted message is then decrypted using the function decrypt() with the key used before. Finally, the decrypted message is printed out.

This example code what generated by ChatGT and is being used for educational reasons and may not provide strong enough encryption for many things. For more secure encryption, it is encouraged to use established encryption algorithms and libraries.


We will not either until we have access to your code. We also need to know the language. Please provide a Repl link (by going into the editor and copying the URL at the top of the browser) and paste it here.

I am going to assume that your Repl is and that your language is Python. Is this correct?

If your language is Python, please update your post to say Code Help → Python.

@KAlexK @SalladShooter


Hey @antoniolopesuk!

Your Repl has an .html file, are you trying to use Flask with Python (your Python wont work with the HTML if it isn’t flask)? If so just create a Flask Repl.


Not necessarily, there are multiple web frameworks out there

@QwertyQwerty88 I believe they didn’t link them together though.

Are we sure this is even Python? I saw that @UMARismyname changed the category to Python, but the OP never actually specified it.


Yeah, there’s no reason to think it would be.


@9pfs1 I just put if it is python then the code. I asked the language they were using (haven’t heard back). I only did the python code since a lot of people do use python for this kind of thing.

This is Python because I think they are doing the encryption in Python and serving it in html.

We did find their Repl a bit ago and it should be somewhere above. It’s a Python Repl so I consider it Python

Sorry for the late reply!

1 Like

1 Like