Caesar Cipher: A simple encryption
Caesar Pypher
This is the Caesar Cipher encryption implemented in Python.
Motivation
I did this before in JS to help a friend. Now took it to Python and poshed it up a bit to give beginners easy examples of how to
- import own modules
- define, init and use own classes
- implement a very basic menu
and whatever you may find useful.
Usage
Menu and functions are somewhat self explanatory.
The entry of the cryptokey is kept secret. It shows no output.
From Wikipedia: [...] each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet [...]
This fixed number is what I call cryptokey in both interface and code.
Known bug
At one point I pasted a longer message. The soft line break was considered a regular one and messed up the output.
Unfortunately I am not able to reproduce this behavior.
In the settings I switched "Wrapping" from soft to none and back. Perhaps that did the trick.
Warning
An encrypted message can only be decrypted with the proper cryptokey. Otherwise no information will be accessible.
You said:
An encrypted message can only be decrypted with the proper cryptokey. Otherwise no information will be accessible.
I wrote a brute force decrypter: https://repl.it/@PYer/Ceaser-Cipher-Brute-Force
A ceasar cipher is not that secure. (Unless your living in th1 1500s).
This is a really cool project though! I made one myself but this is MUCH better. The style and menu are amazing!
Really cool!
I played around with your Brute Force Decrypter. Good job! Worked pretty well on the phrase
Fcnz Rtt Fcnz Fcnz Onpba naq Fcnz
I noticed 2 things though:
- the last character appears twice: extra "z" at output
- the last output line is redundant: it's the input
Meanwhile I did my own Brute Force Decrypter, also enhanced my program otherwise. Have a look if you like.
Cheers
Hey! Cool implementation of the brute force feature. Thanks for pointing out those errors (though I'm probably not going to go through and find the time to fix them,
lol) @Codejira
I was wondering though about a simple AI or something that searches for real english in all of the brute forced results. That way it could output only the legit text, and then ask if thats what the person is looking for. if not, it prints all results. I'm going try and create that.
Here, @Codejira. I wrote a list of commonly used words, and looked for them in the translated message. If it was in there, I printed it first, and then asked the user if it was the decoded message. If not, it printed all the other options. It's the same repl that I previously linked, but here it is again: https://repl.it/@PYer/Ceaser-Cipher-Brute-Force
Works like a charm! Tried it with
Hello darkness my old friend
I cheated and looked up your code first
Next I will look into this clever any(iterable)
function and add it to my toolbox.
yeah. it basically checks to see if any valuable in the iterable evaluates to True
. kind of handy to see if there is any similarity between a list and another list. @Codejira
For example, any(True, False, False) #True
Another one, any(False, False, False) #False
What I do is use the basic template of:
any(variable in list1 for variable in list2)
This allows me to iterate over every item in list2
to check and see if it is in list1. if the item from list2
is in list1
it evaluates two True
and appends it to the iterable that is passed into the any()
function. If not, then False
is appended to the iterable. Then the any
function iterates through it and then returns True
if there is any True
value in the iterable.
I don't use it often, but it is the best solution I know for the situation.
I came up with a new version of encryption I think is good.: https://repl.it/@jimeastman/The-Z-Cipher
The name of the encryption is just random made up name.