Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    Hi, I am currently trying to write a program, for school, in order to encrypt and de-rypt a inputted message. My code currently works but it is not fully complete. I am having trouble trying to allow it to enter an offset from values from 2-26 and I am having trouble making it repeat the question then carry on with the code until it gets the correct value. Right now it just says invalid message when a wrong number is entered but still carries on with the code. Also I need the encrypted or decrypted message to only be in the alphabet no other symbols or keys. Can anyone help please? This is my code currently.

    result = ''
    message = ''
    choice = ''

    offset=int(input("Enter an offset: "))
    if offset >25 or offset <0:
    print("Invalid offset, please enter another offset: ")
    else:
    print("Okay")


    while choice != '3':
    choice = input("\nDo you want to encrypt or decrypt the message?\nEnter 1 to Encrypt, 2 to Decrypt, 3 to Exit Program: ")

    if choice == '1':
    message = input("\nEnter the message to encrypt: ")

    for i in range(0, len(message)):
    result = result + chr(ord(message[i]) - offset)

    print (result + '\n\n')
    result = ''

    elif choice == '2':
    message = input("\nEnter the message to decrypt: ")

    for i in range(0, len(message)):
    result = result + chr(ord(message[i]) + offset)

    print (result + '\n\n')
    result = ''

    elif choice != '3':
    print ("You have entered an invalid choice. Please try again.\n\n")
    Offline

    12
    ReputationRep:
    Go to StackOverflow and post this question. You'll get more responses there.
 
 
 
Poll
Do you agree with the PM's proposal to cut tuition fees for some courses?
Useful resources

Study tools

Rosette

Essay expert

Learn to write like a pro with our ultimate essay guide.

Thinking about uni already?

Thinking about uni already?

See where you can apply with our uni match tool

Student chat

Ask a question

Chat to other GCSE students and get your study questions answered.

Creating

Make study resources

Create all the resources you need to get the grades.

Planner

Create your own Study Plan

Organise all your homework and exams so you never miss another deadline.

Resources by subject

From flashcards to mind maps; there's everything you need for all of your GCSE subjects.

Papers

Find past papers

100s of GCSE past papers for all your subjects at your fingertips.

Help out other students

Can you help? Study help unanswered threads

Groups associated with this forum:

View associated groups

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.