# Implementation of Latin Alphabet Cipher in Python

In this article, we will learn how to implement Latin Alphabet Cipher in Python.

The Latin Alphabet Cipher Encryption Technique is one of the soonest and easiest methods of encoding information. It’s basically a sort of replacement cipher method, i.e., each letter of a given input is replaced by its corresponding number as represented in its alphabetical order.

Example

Input: Message = "codespeedy"
Output: The encrypted message is
3 15 4 5 19 16 5 5 4 25

Approach: We are going to convert the character of the string into its ASCII value and made some changes to make the result in alphabet order.

## ASCII Conversion

Python has an inbuilt function ord() that helps to convert character to ASCII value. For example

char = 'c'
print(ord(char))

Output

99

## Python Code for Latin Alphabet Cipher Encryption

1. Tranverse the input string.

2. Now, convert every character of the input string to its ASCII value and subtract it from the ASCII value of alphabet A for Uppercase and a for lowercase characters.
The operation looks like ord(string[i])-ord(“A”)+1

3. Finally, print the result.

def latin_cipher(string):
print("The encrypted message is")
for i in range(len(string)):

if string[i] >= "A" and string[i] <= "Z":
print(ord(string[i])-ord("A")+1, end=" ")

elif string[i] >= "a" and string[i] <= 'z':
print(ord(string[i])-ord("a")+1, end=" ")

if string[i] == " ":
print(string[i])

print()

string = input("Enter the message with only alphabets and spaces: ")
latin_cipher(string)

Output

Enter the message with only alphabets and spaces: CodeSpeedy
The encrypted message is
3 15 4 5 19 16 5 5 4 25
Enter the message with only alphabets and spaces: Python Programming
The encrypted message is
16 25 20 8 15 14
16 18 15 7 18 1 13 13 9 14 7

Also, refer