Encryption in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

13th Apr 2022, 10:10 AM
Jolen Mascarenhas
15 Answers
+ 3
You can get the location of the character using the index method https://code.sololearn.com/cnkjl9T9GSjk/?ref=app
13th Apr 2022, 10:41 AM
Sandeep
Sandeep - avatar
+ 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
13th Apr 2022, 12:27 PM
Dev-117
Dev-117 - avatar
+ 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
13th Apr 2022, 4:05 PM
Ion Kare
Ion Kare - avatar
+ 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
13th Apr 2022, 5:20 PM
Dev-117
Dev-117 - avatar
+ 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...💡
13th Apr 2022, 8:39 PM
Jolen Mascarenhas
+ 2
Jolen Mascarenhas, glad I could help! Good luck on your project!
13th Apr 2022, 8:54 PM
Dev-117
Dev-117 - avatar
+ 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.
13th Apr 2022, 10:45 AM
Sandeep
Sandeep - avatar
+ 1
Thanks Sandeep it work now
13th Apr 2022, 10:48 AM
Jolen Mascarenhas
+ 1
You can do it the Bytes way
13th Apr 2022, 3:59 PM
Ion Kare
Ion Kare - avatar
+ 1
You can decode it The encode only is +1
13th Apr 2022, 4:46 PM
Ion Kare
Ion Kare - avatar
0
Example; Input>> Hello Output>> isqqr
13th Apr 2022, 10:41 AM
Jolen Mascarenhas
0
Thanks Dev-117
13th Apr 2022, 1:34 PM
Jolen Mascarenhas
0
Thanks Ion Kare but along with encoding, I also need to decode it so that the recipient can read the encrypted message
13th Apr 2022, 4:42 PM
Jolen Mascarenhas
0
Hmm... Thanks Ion Kare
13th Apr 2022, 4:47 PM
Jolen Mascarenhas
0
Thanks Dev-117
13th Apr 2022, 8:58 PM
Jolen Mascarenhas