Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #1
- key = 7
- message = "Hello"
- def encrypt(message, key):
- message = message.lower()
- secret = ""
- for c in message:
- if c in "abcdefghijklmnopqrstuvwxyz":
- num = ord(c)
- num += key
- if num > ord("z"):
- num -= 26
- elif num < ord("a"):
- num += 26
- secret = secret + chr(num)
- else:
- # don't modify any non-letters in the message; just add them as-is
- secret = secret + c
- return secret
- #2
- key = -7
- message = "Hello"
- def decrypt(message, key):
- message = message.lower()
- secret = ""
- for c in message:
- if c in "abcdefghijklmnopqrstuvwxyz":
- num = ord(c)
- num += key
- if num > ord("z"):
- num -= 26
- elif num < ord("a"):
- num += 26
- secret = secret + chr(num)
- else:
- # don't modify any non-letters in the message; just add them as-is
- secret = secret + c
- return secret
- cypher = decrypt("Hello", -7)
- plaint = encrypt(cypher, 7)
- print cypher
- print plaint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement