import random

def encrypt(n,text):
    result = ""
    for i in range(len(text)):
        char = text[i]

        if char == " " or char == ".":
            result += char
        elif (char.islower()):
            result += chr((ord(char) + n - ord("a")) % 26 + ord("a"))

        else:
            result += chr((ord(char) + n - ord("A")) % 26 + ord("A"))
    return result

texts = [
    "The sun sets in the west.",
    "Birds chirp in the morning.",
    "Life is full of surprises.",
    "Time heals all wounds.",
    "Dreams can come true.",
    "Love conquers all obstacles.",
    "Laughter is the best medicine.",
    "Rainbows follow the rain.",
    "Actions speak louder than words.",
    "Hope never truly abandons us.",
    "Family is always there.",
    "Friends are treasures in life.",
    "Music soothes the soul.",
    "Nature is incredibly beautiful.",
    "Hard work pays off eventually.",
    "Kindness makes the world brighter.",
    "Change is a constant companion.",
    "Knowledge is power, indeed.",
    "Happiness comes from within.",
    "Patience is a virtue, truly.",
    "Life is a precious gift.",
    "Beauty is in every soul.",
    "Forgiveness sets us free.",
    "Challenges make us stronger.",
    "Faith moves mountains, indeed.",
    "The universe is vast, mysterious.",
    "Curiosity fuels great discoveries.",
    "Adventure awaits around every corner.",
    "Perseverance leads to success.",
    "Gratitude enriches our lives daily.",
    "The journey is the destination.",
    "Courage faces fear head-on.",
    "Every cloud has a silver lining.",
    "Tomorrow is a new day.",
    "Memories last a lifetime.",
    "Wisdom comes with experience.",
    "Compassion can change the world.",
    "Unity brings strength and harmony.",
    "Miracles happen every day.",
    "Learning never truly ends.",
    "Respect is the foundation of relationships.",
    "Trust builds sturdy connections.",
    "Imagination sparks innovation and creativity.",
    "Balance is key to a fulfilling life.",
    "Empathy fosters deep understanding.",
    "Generosity brings joy to others.",
    "Honesty builds trust and integrity.",
    "Teamwork achieves great goals.",
    "Optimism brightens the darkest days.",
    "Serenity comes from inner peace.",
    "Knowledge enriches the mind.",
    "Friendship warms the heart.",
    "Silence speaks volumes sometimes.",
    "Independence leads to self-discovery.",
    "Love knows no boundaries or limits.",
    "Respect others' opinions and beliefs.",
    "Memories are timeless treasures.",
    "Laughter strengthens the soul.",
    "Acceptance promotes harmony and tolerance.",
    "Time spent with loved ones is precious.",
    "The Earth sustains all life.",
    "Dreams fuel ambition and drive.",
    "Reflection leads to self-awareness.",
    "Humility opens doors to learning.",
    "Joy is found in the little things.",
    "Mindfulness enhances the present moment.",
    "A smile brightens anyone's day.",
    "Integrity is the cornerstone of character.",
    "Gratitude turns what we have into enough.",
    "Compassion starts with understanding others.",
    "Knowledge empowers and enlightens.",
    "Nature teaches valuable lessons daily.",
    "Love is the language of the heart.",
    "Dreams inspire and motivate us.",
    "Silence calms the restless mind.",
    "Diversity enriches the human experience.",
    "Accept challenges with grace and courage.",
    "A positive attitude changes everything.",
    "Kindness is a universal language.",
    "Learning transforms the mind and soul.",
    "Harmony brings peace and unity.",
    "Respect for nature ensures its preservation.",
    "Love is the essence of life.",
    "Silence is a source of great strength.",
    "Time spent in nature rejuvenates.",
    "Faith fuels hope and perseverance.",
    "Creativity knows no bounds.",
    "Compassion heals wounds and hearts.",
    "The present moment is precious.",
    "Adventure begins at the edge.",
    "Laughter connects souls and hearts.",
    "Friendship makes the world beautiful.",
    "Kindness is contagious and powerful.",
    "Peace starts within the heart.",
    "Forgiveness is a gift to yourself.",
    "Courage lies within every soul.",
    "Love creates endless possibilities.",
    "Gratitude turns what we have into enough.",
    "Joy resides in every heart.",
    "Life is an incredible journey."
]

def TexttoCode():
    n = random.randint(1, 26)
    num_text = random.randint(0, 99)
    run = True
    while run:
        print()
        print("Your text to encode is:", texts[num_text])
        print("It is shifted by", n)
        print()
        answer = input("Your answer: ")
        good_code = encrypt(n,texts[num_text])
        if answer == good_code:
            print("Answer was:", good_code)
            print("Success you're right! Well done!")
            run = False
        elif answer == "idk":
            print("Answer was:", good_code)
            print("You were almost there.")
            run = False
        else:
            print("It's wrong! Try again!")
            print("(If you wanna give up ,type: idk)")
    menu()


def CodetoText():
    n = random.randint(1, 26)
    num_text = random.randint(0, 99)
    run = True
    while run:
        print()
        print("Your text to decode is:", encrypt(n, texts[num_text]))
        print("It is shifted by", n)
        print()
        answer = input("Your answer: ")
        good_text = texts[num_text]
        if answer == good_text:
            print("Answer was:", good_text)
            print("Success you're right! Well done!")
            run = False
        elif answer == "idk":
            print("Answer was:", good_text)
            print("You were almost there.")
            run = False
        else:
            print("It's wrong! Try again!")
            print("(If you wanna give up ,type: idk)")
    menu()

def Hard():
    n = random.randint(1, 26)
    num_text = random.randint(0, 99)
    run = True
    while run:
        print()
        print("Your text to decode is:", encrypt(n, texts[num_text]))
        print()
        answer = input("Your answer: ")
        good_text = texts[num_text]
        if answer == good_text:
            print("Answer was:", good_text)
            print("Success you're right! Well done!")
            run = False
        elif answer == "idk":
            print("Answer was:", good_text)
            print("You were almost there.")
            run = False
        else:
            print("It's wrong! Try again!")
            print("(If you wanna give up ,type: idk)")
    menu()


def menu():
    print()
    print()
    print()
    print("Please choose the mode: a. Text to Code")
    print("                        b. Code to Text")
    print("                        c. Hard")
    print("                        d. Quit")
    answer = input("Enter your answer(a/b): ").lower().strip()
    if answer == "a":
        TexttoCode()
    elif answer == "b":
        CodetoText()
    elif answer == "c":
        Hard()
    elif answer == "d":
        quit()
    else:
        print("Wrong input, please input a letter!")
        menu()


menu()