0

So I'm asking if it is possible to make some text like hidden here is a example: **

code = input("Whats the code? ")
if code == ('1401'):
    print('Congrats you got it that is the end good job thanks for playing!!!')
else:
    print('Nope go back a couple files to get the right answer.')

** so I got this little thing and as you can see you can just look at the code 1401 and I don't want anyone to see this when they Ctrl C and Ctrl V into a IDE so is there anyway that is possible to make that "code" hidden?

4
  • 3
    Short answer: no. Longer answer: you'd need to either obfuscate your code, which makes it really hard to maintain, or you'd need to store the code somewhere the user doesn't have access to (such as a database) and fetch it when necessary. If the user is using the same computer the code is running on, it's nearly impossible to prevent them from finding the code if they know what they're doing. Commented Apr 16, 2021 at 15:29
  • Where exactly will your code be posted for others to see? Commented Apr 16, 2021 at 15:32
  • 2
    @GreenCloakGuy it is possible with crypto hashes. Commented Apr 16, 2021 at 15:32
  • Just hash the code and use that to check the condition rather than the code itself Commented Apr 16, 2021 at 15:33

3 Answers 3

3

One way is using cryptographic hashes, for example, bcrypt:

import bcrypt
code_hash = b'$2b$12$7H/JM5RD3dx1sQo3kICV3.ubESHcl3ZM5TbVwcGly9Nw0Rl1j4f6O'
if bcrypt.checkpw(code.encode(), code_hash):
    print('Congrats you got it that is the end good job thanks for playing!!!')
else:
    print('Nope go back a couple files to get the right answer.') 
Sign up to request clarification or add additional context in comments.

Comments

0

If the user has access only to the code file, you could store the secret code in another file (such as a .txt file) and have your program read the file to get the code.

1 Comment

@404BrainNotFound Not a problem. Once your problem is solved, you'll want to mark an answer as correct to signal to posters that you do not require further help.
0

Similar to another answer, you could use hashlib like this:

import hashlib

answer = b'\xaf\xd6y\xcd?\x9a\x81\xfd\x9c\xe0.d4\xa2O\x84\x897\xf0\x99\t\xfa\xbc\xc3\xb3x\x1e\x06\x03n(L'
code = input("Whats the code? ")
user_answer = hashlib.sha256()
user_answer.update(code.encode())
if user_answer.digest() == (answer):
    print('Congrats you got it that is the end good job thanks for playing!!!')
else:
    print('Nope go back a couple files to get the right answer.')

You can get the value to compare against by adding this at the end of this code (it will tell you the hashed value of your input):

print(user_answer.digest())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.