{"id":12562,"date":"2021-09-30T12:00:56","date_gmt":"2021-09-30T06:30:56","guid":{"rendered":"https:\/\/python-programs.com\/?p=12562"},"modified":"2021-11-22T18:34:39","modified_gmt":"2021-11-22T13:04:39","slug":"python-program-to-implement-the-latin-alphabet-cipher","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-implement-the-latin-alphabet-cipher\/","title":{"rendered":"Python Program to Implement the Latin Alphabet Cipher"},"content":{"rendered":"
Explore complete java concepts from the Java programming examples<\/a> and get ready to become a good programmer and crack the java software developer interview with ease.<\/p>\n We will learn how to use Python to implement the Latin Alphabet Cipher.<\/p>\n The Latin Alphabet Cipher Encryption Technique is one of the quickest and most straightforward methods of encoding data. It’s essentially a replacement cipher method, in which each letter of a given input is replaced by its matching number as represented alphabetically.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to implement the Latin Alphabet Cipher in Python.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease. We will learn how to use Python to implement the Latin Alphabet Cipher. The Latin Alphabet Cipher Encryption Technique is one of the quickest and most straightforward methods of …<\/p>\nGiven string =Hello this is BTechGeeks<\/pre>\n
The encrypted message of the given string{ Hello this is BTechGeeks }is :\r\n8 5 12 12 15 \r\n20 8 9 19 \r\n9 19 \r\n2 20 5 3 8 7 5 5 11 19<\/pre>\n
Given string = btechgeeks python<\/pre>\n
The encrypted message of the given string{ btechgeeks python }is :\r\n2 20 5 3 8 7 5 5 11 19 \r\n16 25 20 8 15 14<\/pre>\n
Python Program to Implement the Latin Alphabet Cipher in Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Give the string as static input(which consists of only alphabets and spaces) and store it in a variable\r\ngivenstring = \"Hello this is BTechGeeks\"\r\nprint('The encrypted message of the given string{', givenstring, '}is :')\r\n# Iterate through the characters of the string using For loop.\r\n# We can calculate the ASCII value of the character using the ord() function.\r\nfor m in givenstring:\r\n # Now, transform each input string character to its ASCII value\r\n # and subtract it from the ASCII\r\n # value of alphabet A for uppercase characters and 'a' for lowercase ones.\r\n if (m >= \"A\" and m <= \"Z\"):\r\n # The operation is written as ord(givenstring[i])-ord(\u201cA\u201d)+1 for uppercase letters.\r\n print(ord(m)-ord(\"A\")+1, end=\" \")\r\n elif (m >= \"a\" and m <= 'z'):\r\n # ord(givenstring[i])-ord(\u201ca\u201d)+1 for lowercase letters.\r\n print(ord(m)-ord(\"a\")+1, end=\" \")\r\n # If the character is space then print it(That is printing\r\n # space character without endl which makes it to print in next line)\r\n if m == (\" \"):\r\n print(m)\r\n<\/pre>\n
The encrypted message of the given string{ Hello this is BTechGeeks }is :\r\n8 5 12 12 15 \r\n20 8 9 19 \r\n9 19 \r\n2 20 5 3 8 7 5 5 11 19<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\n
\n
# Give the string as user input(which consists of only alphabets and spaces)\r\n# using input() and store it in a variable.\r\ngivenstring = input('Enter some random string = ')\r\nprint('The encrypted message of the given string{', givenstring, '}is :')\r\n# Iterate through the characters of the string using For loop.\r\n# We can calculate the ASCII value of the character using the ord() function.\r\nfor m in givenstring:\r\n # Now, transform each input string character to its ASCII value\r\n # and subtract it from the ASCII\r\n # value of alphabet A for uppercase characters and 'a' for lowercase ones.\r\n if (m >= \"A\" and m <= \"Z\"):\r\n # The operation is written as ord(givenstring[i])-ord(\u201cA\u201d)+1 for uppercase letters.\r\n print(ord(m)-ord(\"A\")+1, end=\" \")\r\n elif (m >= \"a\" and m <= 'z'):\r\n # ord(givenstring[i])-ord(\u201ca\u201d)+1 for lowercase letters.\r\n print(ord(m)-ord(\"a\")+1, end=\" \")\r\n # If the character is space then print it(That is printing\r\n # space character without endl which makes it to print in next line)\r\n if m == (\" \"):\r\n print(m)\r\n<\/pre>\n
Enter some random string = btechgeeks python\r\nThe encrypted message of the given string{ btechgeeks python }is :\r\n2 20 5 3 8 7 5 5 11 19 \r\n16 25 20 8 15 14<\/pre>\n
\n