Checking "encryption" and "decryption" of Caesar Cipher using strings in python
<p>I was supposed to create strings in my python function to show that the encryption and decryption of my code was working properly. Below is my code. </p>

<pre><code>def encrypt1():
    plain1 = input('Enter plain text message: ')
    cipher = ''

    for each in plain1:
        c = (ord(each)+3) % 126

        if c &lt; 32: 
            c+=31

    cipher += chr(c)

    print ("Your encrypted message is:" + cipher)

encrypt1()
</code></pre>

<p>1.) I get the "Inconsistent use of tabs and spaces" error</p>

<p>2.) How should I input set, constant strings to get the wanted input check if my code works (for example, type in meet and get the correct input, etc)</p>

<p>Your code is mostly fine but there are a few issues that I've pointed out:</p>

<ol>
<li>Your indenting is off. The line <code>cipher += chr(c)</code> should be indented to match the things in the for loop</li>
<li>The function encypt1() shouldn't take a parameter; you are setting plain1 in the method itself so you can declare it there</li>
<li>If you want to deal with just lowercase letters, you should be doing % 123 (value of 'z') and the if clause should check if <code>c &lt; 97</code>. If you want to wrap around printable ascii what you're doing is fine.</li>
</ol>

<p>This gives:</p>

<pre><code>    def encrypt1():
        plain1 = input('Enter plain text message: ')
        cipher = ''
        for each in plain1:
            c = (ord(each)+3) % 126
            if c &lt; 32: 
                c+=31
            cipher += chr(c)
        print ("Your encrypted message is:" + cipher)
</code></pre>

<p>Because you want to be able to test this on multiple strings, you would want to pass plain1 as a parameter to the function. But you also want the user to be able to input plain1 if a parameter isn't passed in to the function. For that I would suggest a default parameter. Look at the commented code below:</p>

<pre><code>def encrypt1(plain1=""):        # if no argument is passed in, plain1 will be ""
    if not plain1:              # check if plain1 == "" and if so, read input from user
        plain1 = input('Enter plain text message: ')
    cipher = ''
    for each in plain1:
        c = (ord(each)+3) % 126
        if c &lt; 32: 
            c+=31
        cipher += chr(c)
    return cipher               # rather than printing the string, return it instead
</code></pre>

<p>So to test this you could do:</p>

<pre><code>test_strings = ['hello world', 'harambe', 'Name', 'InputString']

for phrase in test_strings:
    print ("Your encrypted message is:" + encrypt1(phrase))
</code></pre>

<p>Which gives the output:</p>

<pre><code>Your encrypted message is:khoor#zruog
Your encrypted message is:kdudpeh
Your encrypted message is:Qdph
Your encrypted message is:LqsxwVwulqj
</code></pre>

python encryption caesar-cipher