diff --git a/Encryption.ipynb b/Encryption.ipynb new file mode 100644 index 0000000..4e8f852 --- /dev/null +++ b/Encryption.ipynb @@ -0,0 +1,187 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Message Encryption & Decryption\n", + "\n", + "## Yidi Chi\n", + "## POL-team, Ironhack, 22/10/2020\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Encryption is the process of encoding information in such a way that only authorized parties can access it. It allows us to securely protect data which we don’t want just anyone to see or access.\n", + "\n", + "#### What is meant By Encryption?\n", + "\n", + "Encryption is a process which transforms the original information into an unrecognizable form. This new form of the message is entirely different from the original message.Encryption is usually done using key algorithms.\n", + "\n", + "#### What is meant by Decryption?\n", + "\n", + "Decryption is a process of converting encoded/encrypted data in a form that is readable and understood by a human or a computer. This method is performed by un-encrypting the text manually or by using keys used to encrypt the original data.\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### About DEMO :\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- First, create encrypt function which accepts the string I'm going to encrypt along with key as a 2nd argument with which we are going to do encryption.\n", + "\n", + "This function encrypt the string message based on the key you suggest.\n", + "\n", + "- Second create a decrypt function after the encrypt function which will then decode our encrypted message back to its original message.\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter your message:hello\n", + "Enter your key:4\n" + ] + } + ], + "source": [ + "messages = input('Enter your message:')\n", + "\n", + "key = int(input('Enter your key:'))\n", + "\n", + "letters1 ='abcdefghijklmnopqrstuvwxyz'\n", + "letters2 =letters1.upper()\n", + "letters= letters1+letters2\n", + "\n", + "def encrypt(message, key):\n", + " encrypted=''\n", + " for i in message:\n", + " text=letters.find(i)\n", + " newtext=(text+key)%26\n", + " encrypted+=letters[newtext]\n", + " return encrypted\n", + "\n", + "\n", + "\n", + "def decrypt(message, key):\n", + " decrypted=''\n", + " for i in message:\n", + " text1=letters.find(i)\n", + " newtext1=(text1-key)%26\n", + " decrypted+=letters[newtext1]\n", + " return decrypted\n", + "\n", + "\n", + "message=messages\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'lipps'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "encrypt(message, key)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "#print(encrypt(message, key))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "encrypted_message=encrypt(messages, key)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "decrypt(encrypted_message, key)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}