0% found this document useful (0 votes)
12 views

Lab1 - Pythone

The document is from Arusha Technical College about a student named Donald Mwakatoga. It discusses implementing a Caesar cipher in Python. The Python code gets a plain text message and encryption key from the user. It initializes arrays for the alphabet and encrypted text. The code iterates through each character, finds its index in the alphabet, shifts it by the key, takes the modulus to wrap around the alphabet, and saves the encrypted character in the output array. It prints the encrypted text. The application successfully encrypts plain text using the Caesar cipher and key.

Uploaded by

Denis Priscus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lab1 - Pythone

The document is from Arusha Technical College about a student named Donald Mwakatoga. It discusses implementing a Caesar cipher in Python. The Python code gets a plain text message and encryption key from the user. It initializes arrays for the alphabet and encrypted text. The code iterates through each character, finds its index in the alphabet, shifts it by the key, takes the modulus to wrap around the alphabet, and saves the encrypted character in the output array. It prints the encrypted text. The application successfully encrypts plain text using the Caesar cipher and key.

Uploaded by

Denis Priscus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ARUSHA TECHNICAL COLLEGE

DEPARTMENT: INFORMATION COMMUNICATION TECHNOLOGY


PROGRAM: COMPUTER SCIENCE
NAME: DONALD DONALD MWAKATOGA
ADMISSION: 21050513023
Objective:
Demonstrating the Caesar cipher's implementation in Python.
Programing language used:
Python programing language
Methodology used to implement Caesar Cipher encryption using Python language
The Caesar Cipher encryption algorithm is implemented in this Python code, which requests
a plain text message from the user along with an alphabet shift key. An array is initialized to
hold the alphabet, and another is initialized to hold the encrypted text. The program searches
the alphabet array for matches as iteratively goes over each character in the user-provided
plain text. It uses the key to determine the encrypted character's index for each match, then
saves the result in the encrypted text array. With the assumption that the input consists solely
of lowercase letters, the software outputs the encrypted text that results.

# Get user input for the plain text to encrypt


plain_text = input("Please give us plain text to encrypt: \t")

# Get user input for the key used in the cipher and convert it to an integer
key = int(input("Please give us the key for the cipher: \t"))

# Define the alphabet as a string


alphabets = 'abcdefghijklmnopqrstuvwxyz'

# Initialize an empty string to store the encrypted text


cypher_text = ''

# Iterate through each character in the input plain text


for char in plain_text:
# Check if the character is in the alphabet
if char in alphabets:
# Calculate the index of the encrypted character and wrap around using modulus
cyphered_char_index = (alphabets.index(char) + key) % 26
# Append the encrypted character to the cypher_text string
cypher_text += alphabets[cyphered_char_index]

# Print the final encrypted text


print(cypher_text)

Results:
The application uses the Caesar Cipher and input cryptographic key to encrypt the plain text
and successfully encrypted.

You might also like