An Encryption And Decryption Program
It's back to the schedule, so here's my latest creation. A python program that does encryption and decryption in both the Caesar Cipher and the Vigenère Cipher. When given a message with a key, the program shall input the two into an encryption function which will return the encrypted message unless there are errors. For show, the encrypted message is outputted to the console and then placed into the decryption function along with its key, which returns the message decrypted.
The Caesar Cipher does the following:
The Vigenère Cipher does the following:
Both of these ciphers functions also have decipher functions. These practically do the same thing, but in reverse. They do require the keys used to encrypt.
That's all I got to show today. These were done a few days before, but were for something other project I was doing. I've now decided to post them here.
Currently, I am looking into Pygame. Perhaps by next week I may give you some basic game. But that will all have to wait until later. See you next time!
ZnkQk!LuxZnk\omtkxkOyV!znut
xbhuhnrrnhzynehaoztqlhurhmkym
The Caesar Cipher does the following:
- Get the message and key
- Validate message and key
- Make sure the message is a string made up of ASCII characters (and only visible ones; the ones from char 33 to 126) and the key is an integer
- Print to console the problems and stop if validation fails
- For every letter in the message
- Get the current letter and its ASCII number
- If the ASCII number of the current letter plus the key is above 126
- Add to the output string the character with an ASCII number equal to the ASCII number of the current letter plus the key minus 94
- Else
- Add to the output string the character with an ASCII number equal to the ASCII number of the current letter plus the key
- Return the output string
The Vigenère Cipher does the following:
- Get the Message and Key
- Validate the Message and Key
- Make sure both are strings that contain alphabetical letters
- Print to console and problems and stop if validation fails
- For i in the length of Message
- Get A which is the index of the i'th letter in a array containing the alphabet
- Get B which is the index of the letter in Key at point i % length of the key string
- Add to the output string the letter in the alphabet array at the index of (a + b) % 26
- Return the output string
Both of these ciphers functions also have decipher functions. These practically do the same thing, but in reverse. They do require the keys used to encrypt.
That's all I got to show today. These were done a few days before, but were for something other project I was doing. I've now decided to post them here.
Currently, I am looking into Pygame. Perhaps by next week I may give you some basic game. But that will all have to wait until later. See you next time!
ZnkQk!LuxZnk\omtkxkOyV!znut
xbhuhnrrnhzynehaoztqlhurhmkym
Comments
Post a Comment