Friday, December 21, 2018

Encryption using Dictionary in py

Try this piece of code for encrypting in python:

my_dict={"A":"D","B":"E","C":"F","D":"G","E":"H",
"F":"I","G":"J","H":"K","I":"L","J":"M","K":"N",
"L":"O","M":"P","N":"Q","O":"R","P":"S","Q":"T",
"R":"U","S":"V","T":"W","U":"X","V":"Y","W":"Z",
"X":"A","Y":"B","Z":"C","1":"5","2":"6","3":"7",
"4":"8","5":"9","6":"0","7":"1","8":"2","9":"3",
"0":"4"," ":" "}

message=input("Enter msg to encrypt: ").upper()
encrypted=""

>>> for letters in message:
...     if letters in my_dict:
...             encrypted+=mydict[letters]
...     else:
...             encrypted+=letters
... print(encrypted.lower())

No comments:

Post a Comment