# Arup Guha
# 8/21/2023
# Code Example showing encrypt/decrypt functions for class exercises
# 2 and 3. It's fairly easy to show for both functions that the
# encryption and decryption functions are exactly the same.

# plain must be a lowercase alphabetic string.
# Returns the encrypted string using the technique from question 2
def swapOpposite(plain):

    ans = ""
    for x in plain:

        # Mathematically this is what our flip cipher is doing.
        flipnum = 25 - (ord(x) - ord('a'))

        # Append to my running answer doing annoying Python stuff.
        ans = ans + chr( ord('a') + flipnum )

    return ans

# plain must be a lowercase alphabetic string.
# Returns the encrypted string using the technique from question 2
def swapNext(plain):

    ans = ""
    for x in plain:

        # Get the number.
        num = ord(x) - ord('a')

        # Add 1 for even numbers.
        if num%2 == 0:
            num += 1

        # Subtract 1 for odd numbers.
        else:
            num -= 1

        # Append to my running answer doing annoying Python stuff.
        ans = ans + chr( ord('a') + num )

    return ans

# Just test both functions.
print(swapOpposite("theparkingsituationwillbebetternextweek"))
print(swapOpposite("gsvkziprmthrgfzgrlmdrooyvyvggvimvcgdvvp"))
print(swapNext("forcenturiesthesimplemonoalphabetic"))
print(swapNext("epqdfmsvqjftsgftjnokfnpmpbkogbafsjd"))
    
