Reputation: 1
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?
Upvotes: 0
Views: 552
Reputation: 34282
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.')
Upvotes: 3
Reputation: 30
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())
Upvotes: 0
Reputation: 655
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.
Upvotes: 0