+ 1
Encryption in python
LETTERSU='ABCDEFGHIJKLMNOPQRSTUVWXYZ' LETTERSL=LETTERSU.lower() LETTERS2U='TFOESGHIJKPQCDRXBUVWLAMNYZ' LETTERS2L=LETTERS2U.lower() message=input("Enter your message >") outpt="" for i in message: if i in LETTERSU: #i need something that finds the location of the character i in the LETTERSU such as LETTERSU[1] and replace it with LETTERS2U[1] and store in the output. outpt+=LETTERS2U[a] if i in LETTERSL: #same as previous comment... outpt+=LETTERS2L[a] print(outpt) #Any help is greatly appreciated #thanks for ur time... # |. /\. /\. |√-- |. | /· # |. / \/ \. |___|. |/· # |. / \. |\. |\. #__|. / \. | \. | \. https://code.sololearn.com/c3zszXZ36cik/?ref=app
15 Answers
+ 3
You can get the location of the character using the index method
https://code.sololearn.com/cnkjl9T9GSjk/?ref=app
+ 3
For more secure encryption you can use the python library: hashlib
Example:
import hashlib
string = input("Enter String: ")
sha = hashlib.sha256()
sha.update(string.encode())
print(sha.hexdigest())
This is using sha256, often used in password hashing (What the password should looks like in the database) and sha256 (as shown above) is quite secure. Also should be noted that you cannot de-hash it or de-encrypt it.
https://replit.com/@Reference-Code/Login-with-sqlite for reference
https://code.sololearn.com/c5H7ulFXAC5Z/?ref=app
+ 2
https://code.sololearn.com/cOUfJfrpRc29/?ref=app
i've edited it to decode message
the chr & Z are just commas or spaces can be removed
+ 2
This might be what you are looking for. It is not very safe/secure however but it should so what you need it to do.
You can only enter in letters otherwise it will crash at the moment, but hopefully you can use it to get what you need to do! Let me know if you need me to explain it too.
https://code.sololearn.com/c6C647MYXmh3/?ref=app
+ 2
Thanks Dev-117. I have tried it before but with a lot of if and else statements. So basically my code was a bit too long...😅😅
I was planning to create a program similar to enigma such that if I enter suppose a letter 'e' twice, the encrypted word should not have the same letters... And with this, a key should be generated so that you can Decrypt it later.
I'm still working on it
Anyways, thanks for your help 👍
It gives so many ideas...💡
+ 2
Jolen Mascarenhas, glad I could help! Good luck on your project!
+ 1
Edit: just saw the input and output, you need to also change the "message" to uppercase because "message" inputted by the user is in lowercase but your "LETTERSU" string have all the uppercase characters.
2Edit: made a mistake, it will not lead to the desired behaviour, instead add the similiar statement in the second if condition, I have updated the code.
+ 1
Thanks Sandeep
it work now
+ 1
You can do it the Bytes way
+ 1
You can decode it
The encode only is +1
0
Example;
Input>> Hello
Output>> isqqr
0
Thanks Dev-117
0
Thanks Ion Kare but along with encoding, I also need to decode it so that the recipient can read the encrypted message
0
Hmm... Thanks Ion Kare
0
Thanks Dev-117