# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Caesar Cipher

alphabet = 'abcdefghijklmnopqrstuvwxyz'

input_text = 'hello'

# ## Build a very simple version

output = ''
for char in input_text:
    alpha_index = alphabet.find(char)
    output = output + alphabet[alpha_index+3]
print(output)    

# ## What if cipher index goes beyond end of alphabet?

output = ''
for char in input_text:
    alpha_index = alphabet.find(char)
    output = output + alphabet[alpha_index+30]
print(output)

30%26


# ## Write a function to deal with shift

def shift_amount(i):
    '''Will determine the shift, taking into account the length of the alphabet. Takes integer - returns integer'''
    return i%26


# ## Now test with shift > 26

output_1 = ''
for char in input_text:
    alpha_index = alphabet.find(char)
    output_1 = output_1 + alphabet[shift_amount(alpha_index+30)]
print(output_1)    


# ## A complete function

def encrypt(text,required_shift):
    out_string = ''
    text = text.lower()
    for char in text:
        if char not in alphabet:
            out_string = out_string + char
        else:    
            alpha_index = alphabet.find(char)
            out_string = out_string + alphabet[shift_amount(alpha_index +required_shift)]
    return out_string



new_string = 'Once upon'
shift = encrypt(new_string,5)

shift

# +
basker = '''I confess at these words a shudder passed
through me. There was a thrill in the doctor’s voice
which showed that he was himself deeply moved
by that which he told us. Holmes leaned forward
in his excitement and his eyes had the hard, dry
glitter which shot from them when he was keenly
interested.'''

encrypt_basker = encrypt(basker,10)
print(encrypt_basker)
# -

print(encrypt(encrypt_basker,-10))

question_text = 'The cat sat on the mat'
print(encrypt(question_text,11))

question_text.

StarcoderdataJupyterScriptsDedupFiltered