Posted on:

28 Dec 2022

0

My solution using List and Dictionaries

def encrypt(text,shift):
    text=text.lower()
    alphabet_shifted=list(str.ascii_lowercase)
    alphabet=list(str.ascii_lowercase)
   # First we create our list of alphabets
    for i in range(shift):
        alphabet_shifted.append(alphabet_shifted[0])
        alphabet_shifted.remove(alphabet_shifted[0])
    # The loop is used to shift the alphabet list 
    dics=dict(zip(alphabet,alphabet_shifted))
    # We create a dictionary which keys are alphabets and values are shifted alphabets 
    encrypted_word=''
    for char in text:
        if char not in alphabet:
            encrypted_word+=char
        else:
            encrypted_word+=dics.get(char)
    # Using our dictionary we can encrypt our text using the values 
    return encrypted_word
0 answers ( 0 marked as helpful)

Submit an answer