Okay, the encryption algorithm idea was stupid. But I still made an encryption program. I got the absolute most possible frustrating situation. The program doesn't work in the console window. It spits out a giant error (probably recursion judging how many errors it got), but it DOES work in IDLE. So the only way to fix it is manually see the error, which I've tried to do again and again with no success. So, the error comes after you input the message. So here's the code:
import os
import random
if os.name == "nt":
os.system("color 48")
os.system("title Encryptor/Decryptor")
def clear():
os.system("cls")
else:
def clear():
os.system("clear")
def menu():
clear()
print ("")
print ("Encryptor/Decryptor")
print ("-------------------")
print ("1) Encrypt Message ")
print ("2) Decrypt Message ")
print ("-------------------")
menu_choice = input ("Choose one: ")
if menu_choice != "1":
if menu_choice != "2":
clear()
print ("")
print ("Please type a valid choice!")
input ()
menu()
if menu_choice == "1": encrypt()
if menu_choice == "2": decrypt()
def encrypt():
clear()
print ("")
print ("------------------------------------")
print ("1) Use computer generated number key")
print ("2) Manually key ")
print ("------------------------------------")
encrypt_choice = input ("Choose one: ")
if encrypt_choice == "1":
key = list(str(random.random()).split(".")[1])
else:
clear()
print ("")
key = list(str(input("Please type key: ")))
show = ""
while 1:
clear()
print ("")
print (show)
print ("Type S to show key, H to hide key ")
print ("Type R to change key ")
print ("-----------------------------------")
message = list(input ("Please type a message to be encrypted: "))
if "".join(message).lower() == "s":
show = str("Key is: " + str("".join(key)))
continue
if "".join(message).lower() == "r":
encrypt()
if "".join(message).lower() == "h":
show = ""
continue
break
while len(key) < len(message):
key += key
spaces = 0
encrypt_list = []
shift = 1
for loop in range((len(message))):
shift += 1
if str(message[loop]) == ' ':
spaces += 1
else:
if str(message[loop]) == ' ':
spaces += 1
''
if str(message[loop]) != ' ':
if str(message[loop]) != ' ':
if str(message[loop]) == str(key[loop-spaces]):
encrypt_list.append(message[loop])
else:
if (shift % 2) == 0:
loop_ord = str(chr(ord(key[loop-spaces])+ord(message[loop])))
else:
if ord(str(message[loop])) < ord(str(key[loop-spaces])):
loop_ord = "9u" + str(chr(ord(key[loop-spaces])-ord(message[loop])))
else:
loop_ord = chr(ord(message[loop])-ord(key[loop-spaces]))
encrypt_list.append(loop_ord)
print ("")
print ("Encrypted message is: ", "".join(encrypt_list))
if show == "":
print ("")
ask = input ("Show key before leaving(Y/N): ")
if ask.lower() == "y":
print ("")
print ("Key is: " + str("".join(key)))
input ()
menu()
def decrypt():
menu()
menu()
Help would GREATLY be appreciated.