Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Trying to make an encrypted message system
-
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
-
Try bit flipping... https://github.com/cclauss/Ten-lines-or-less/blob/master/bit_filpper.py
-
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'
-
Thank you so much everyone! This has helped :)
-
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)
-
@Spencer1221 If you put that code inside triple back ticks (
`
) it will show as formatted code:``` your code here ```
-
Oh ok thanks @Webmaster4o
-
now: make your code work with both upper and lowercase alphabet!