Program to Encode or Decode a Secret Message in Python

Enter your message and the following program will encode or encrypt it. Also it can decode or decrypt your message.

import random

rc1 = chr(random.randint(ord("a"), ord("z")))
rc2 = chr(random.randint(ord("a"), ord("z")))
rc3 = chr(random.randint(ord("a"), ord("z")))
rc4 = chr(random.randint(ord("a"), ord("z")))
rc5 = chr(random.randint(ord("a"), ord("z")))
rc6 = chr(random.randint(ord("a"), ord("z")))

user_input = input("What you want to do?\n"
      "1. Encode\n"
      "2. Decode\n>>> ")

user_input = eval(user_input)

if user_input == 1:
    toEncode = input("Enter the words you want to encode: ").split(" ")
    for word in toEncode:
        if len(word) < 3:
            print(word[::-1], end=" ")
        else:
            print(rc1+rc2+rc3+word[1:]+word[0]+rc4+rc5+rc6, end=" ")
            
elif user_input == 2:
    toDecode = input("Enter the words you want to decode: ").split(" ")
    for word in toDecode:
        if len(word) < 3:
            print(word[::-1], end=" ")
        else:
            print(word[-4]+word[3:-4], end=" ")
else:
    print("Invalid input")

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes