Hey so I'm new to Python and this app is helping me learn fast. I am wanting to make a module to encrypt messages and to decrypt messages. I'm having some difficulty with solving this. So it would help if someone could have some steps to help me out. Thanks :) love this app though
Forum Archive
Trying to make an encrypted message system
Spencer1221
Mar 19, 2016 - 05:11
ccc
Mar 19, 2016 - 07:22
Try bit flipping... https://github.com/cclauss/Ten-lines-or-less/blob/master/bit_filpper.py
JonB
Mar 19, 2016 - 09:05
Another option: translate (here's a caesar cipher from stackoverflow. )
#! Python2
import string
def caesar(plaintext, shift):
alphabet = string.ascii_lowercase
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
table = string.maketrans(alphabet, shifted_alphabet)
return plaintext.translate(table)
For a simple two-way cipher, rot13 comes built in, using the encode method of str types.
>>> print "Gur rntyr syvrf ng zvqavtug".encode("rot13")
'The eagle flies at midnight'
Spencer1221
Mar 19, 2016 - 16:26
Thank you so much everyone! This has helped :)
Spencer1221
Mar 19, 2016 - 17:03
Thanks so much everyone this was a good learning experience! I made this system with your examples.
import string
char_list = list(string.ascii_letters) + list(string.digits) + list(string.punctuation)
def encrypt(message, key):
alphabet = string.ascii_letters
shifted_alphabet = alphabet[key:] + alphabet[:key]
table = string.maketrans(alphabet, shifted_alphabet)
return message.translate(table)
def decrypt(message, key):
alphabet = string.ascii_letters
shifted_alphabet = alphabet[-key:] + alphabet[:-key]
table = string.maketrans(alphabet, shifted_alphabet)
return message.translate(table)
Webmaster4o
Mar 19, 2016 - 17:07
@Spencer1221 If you put that code inside triple back ticks (`) it will show as formatted code:
```
your code here
```
Spencer1221
Mar 19, 2016 - 17:21
Oh ok thanks @Webmaster4o
JonB
Mar 19, 2016 - 19:59
now: make your code work with both upper and lowercase alphabet!