{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyP6j5Q7GRKgylqaY5knshvj"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"id":"ngryVCsvE2NR","executionInfo":{"status":"ok","timestamp":1720756482587,"user_tz":-540,"elapsed":4,"user":{"displayName":"kuwata.04f Chuo University","userId":"04710876708519006124"}}},"outputs":[],"source":["def encrypt_text(plaintext,key):\n"," ans = \"\"\n"," # iterate over the given text\n"," for ch in plaintext:\n","\n"," # check if space is there then simply add space\n"," if ch==\" \":\n"," ans+=\" \"\n"," # check if a character is uppercase then encrypt it accordingly\n"," elif (ch>='A' and ch<='Z'):\n"," ans += chr((ord(ch) + key - ord('A')) % 26 + ord('A'))\n"," # check if a character is lowercase then encrypt it accordingly\n","\n"," else:\n"," ans += chr((ord(ch) + key - ord('a')) % 26 + ord('A'))\n","\n"," return ans"]},{"cell_type":"code","source":["plaintext = \"i came i saw i conquered\"\n","key = 3\n","print(\"Plain Text is : \" + plaintext)\n","print(\"Shift pattern is : \" + str(key))\n","print(\"Cipher Text is : \" + encrypt_text(plaintext,key))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"3xr7_NRyFJGl","executionInfo":{"status":"ok","timestamp":1720756510747,"user_tz":-540,"elapsed":263,"user":{"displayName":"kuwata.04f Chuo University","userId":"04710876708519006124"}},"outputId":"285deae2-0f86-4a76-d92a-567e8da57735"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["Plain Text is : i came i saw i conquered\n","Shift pattern is : 3\n","Cipher Text is : L FDPH L VDZ L FRQTXHUHG\n"]}]},{"cell_type":"code","source":["plaintext = \"L FDPH L VDZ L FRQTXHUHG\"\n","key = 23\n","print(\"Plain Text is : \" + plaintext)\n","print(\"Shift pattern is : \" + str(key))\n","print(\"Cipher Text is : \" + encrypt_text(plaintext,key))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Bxs0SsImFJ2N","executionInfo":{"status":"ok","timestamp":1720756533797,"user_tz":-540,"elapsed":273,"user":{"displayName":"kuwata.04f Chuo University","userId":"04710876708519006124"}},"outputId":"0bf19ec2-42b3-489b-ea6e-018f6f8b2726"},"execution_count":3,"outputs":[{"output_type":"stream","name":"stdout","text":["Plain Text is : L FDPH L VDZ L FRQTXHUHG\n","Shift pattern is : 23\n","Cipher Text is : I CAME I SAW I CONQUERED\n"]}]},{"cell_type":"code","source":["plaintext = \"VS JR JVFU GB ERCYNPR YRGGREF\"\n","for key in range(6):\n"," print(\"Cipher Text is : \" + encrypt_text(plaintext,-key))"],"metadata":{"id":"2qeFkrgjFjob"},"execution_count":null,"outputs":[]}]}