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:
  1. Get the message and key
  2. Validate message and key 
    1. 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 
      1. Print to console the problems and stop if validation fails
  3. For every letter in the message 
    1. Get the current letter and its ASCII number 
    2. If the ASCII number of the current letter plus the key is above 126 
      1. 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 
    3. Else 
      1. Add to the output string the character with an ASCII number equal to the ASCII number of the current letter plus the key
  4. Return the output string
In a way, it's not exactly the Caesar Cipher. Instead of using only alphabetical letters, it uses ASCII characters such as & and ; as well. I could simply make it use letters only, all that would need is a list of the alphabet.

The Vigenère Cipher does the following:
  1. Get the Message and Key
  2. Validate the Message and Key 
    1. Make sure both are strings that contain alphabetical letters 
      1. Print to console and problems and stop if validation fails
  3. For i in the length of Message
    1. Get A which is the index of the i'th letter in a array containing the alphabet
    2. Get B which is the index of the letter in Key at point i % length of the key string 
    3. Add to the output string the letter in the alphabet array at the index of (a + b) % 26
  4. Return the output string
This one only uses alphabetical letters. It has a list of letters which it gets characters from.

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

Popular posts from this blog

Version 2:The Not-So Barebones Clicker

A Prime Factorization Algorithm that Uses a Text File

Aesthetico Ultimate Designer - A Python Turtle Program