Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Secret Codes! Create a program that will accept a message from the user and eith

ID: 3793125 • Letter: S

Question

Secret Codes!

Create a program that will accept a message from the user and either
encrypt ordecrypt it with the following algorithms:

To encrypt:

- get the character you wish to encrypt

- find the index of that character in the alphabet array

- add the shift offset to the index

- add the increment to the index

- "wrap around" the new index so the result is between 0 and 29

- find the character at the new index

To decrypt:

- get the character you wish to decrypt

- find the index of that character in the alphabet array

- subtract the shift offset from the index

- subtract the increment from the index

- "wrap around" the new index so the result is between 0 and 29

- find the character at the new index

- repeat steps 1-6 for every shift offset

The alphabet is <space>,a-z(lowercase),<period>,<question mark>,
and <comma> in that order.

The increment should be +3 per letter position.

Here is a sample message. Who said it?

f..yqjrnvrpuabefw.j,ddxgcndpxmsdehsomjkcydfygtd.rrp?dgstmvxmf.wo?jxgrneslzifrgzyqv.v

Explanation / Answer

PYTHON CODE FOR ENCRYPTING AND DECRYPTING THE MESSAGE

s_list=' abcdefghijklmnopqrstuvwxyz.?,'
def encryption(msg):
             
    for i in range(0,len(msg)):
      
        j=s_list.index(msg[i])
        j+=3
        if j>29:
            j=abs(29-j)-1
        print(s_list[j],end='')
  

def decryption(msg):
  
    for i in range(len(msg)):
        j=s_list.index(msg[i])
        j-=3
        if j<0:
            j=abs(29-abs(j))+1
        print(s_list[j],end='')
      

if __name__=="__main__":
    msg=input('Enter the message.... ')
    dec_enc=input("Encrypt or Decrypt the message..press 'e' for encryption or 'd' for decryption.. ")
    if dec_enc=='e':
        encryption(msg)
    elif dec_enc=='d':
        decryption(msg)
    else:
        print('enter e or d')

SAMPLE OUTPUT

Enter the message.... hello world
Encrypt or Decrypt the message..press 'e' for encryption or 'd' for decryption.. e
khoorczruog

Enter the message.... khoorczruog
Encrypt or Decrypt the message..press 'e' for encryption or 'd' for decryption.. d
hello world

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote