Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
def encode(message, shift):
	message = message.lower()
	secret = ""
	for c in message:
		if c in "abcdefghijklmnopqrstuvwxyz":
			num = ord(c)
			num += shift
			if num > ord("z"):       
				num -= 26
			elif num < ord("a"):
				num += 26
			secret = secret + chr(num)
		else:
		  secret = secret + c
	return secret
  # this line does nothing. Remove it when you complete the method.

def decode(message, shift):
  
  pass  # this line does nothing. Remove it when you complete the method.

def main():
  msg = input("Your message to encode? ")
  if len(msg) > 0:
	  secret = encrypt(msg)
	  print("The encoded message is:", secret)
  else:
	secret = input("Your message to decode? ")
	if len(secret) > 0:
		msg = decrypt(secret)
		print("The decoded message is:", msg)

  # this line does nothing. Remove it when you complete the method.
  
---"I do not know how to make decode line"---


########################################################################
###                Do not modify anything below here                 ###
########################################################################
if __name__ == '__main__':
  main()


What I have tried:

I couldn't complete decode line
Posted
Updated 25-Mar-20 11:25am

Look at the encode method, and work out how it converts characters - it's not exactly complicated, Caesar Ciphers never are - and just reverse it. Subtract the "secret" value, "undo" the add on value, and use the ordinal value to restore the original character.

It's not complicated, it is your homework not ours , and working out exactly what to do is part of your task!
 
Share this answer
 
1. Your Main block is calling two functions (encrypt/decrypt) and passing just the one parameter. Neither of those functions are defined, what you have are encode/decode; which both have two parameters.

2. From looking at the encode function; it looks like you should do just the opposite, subtracting for some and adding for the others.

... and if you use the number 13 for this you will be creating a simple obfuscation from the 90s known as Rot13
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900