A hint:
(Im a newbie too:D)
message = raw_input('Enter Message:')
newMessage = ''
for char in message:
crypted = ord(char)
newMessage += str(crypted)
outfile = open('CryptedMessage.txt', 'w')
outfile.write(newMessage)
outfile.close()
M.S.
Junior Poster in Training
56 posts since Jul 2011
Reputation Points: 28
Solved Threads: 7
Let's wait for masters to give you a more efficient Hint.
but for now this works for me:
#declare and initialize variables
#string message
newMessage = "" # why three variables
#Intro
print(",---. | ,---. ")
print("|--- ,---.,---.,---.,---|,---.,---. |---',---.,---.,---.,---.,---.,-.-.")
print("| | || | || ||---'| | | | || || ,---|| | |")
print("`---'` '`---'`---'`---'`---'` ` ` `---'`---|` `---^` ' '")
print(" `---' ")
#Prompt the user for the message
message = raw_input("Please enter the message you would like to encode: ")# Or just input in python 3.x
#Loop through message
for ch in message:
encoded = ord(ch)* 6 - 5
newMessage += str(encoded)+ " "
#Print and calculate the new value of message
print(newMessage)
#Open a the file “encryptedmessage.txt”
outfile = open("encryptedmessage.txt", "w")
#Write to file “encryptedmessage.txt”
outfile.write(newMessage)
#Close the file
outfile.close()
M.S.
Junior Poster in Training
56 posts since Jul 2011
Reputation Points: 28
Solved Threads: 7
Also that "+=" what is that? We have not covered this at all. Is there another way of possibly doing it without using this.
that "+=" means add something to original variable.
You can use something like this: newMessage = newMessage + (str(encoded) + " ")
a = "Hello"
a+=" World"
print a
#is the same with:
a = "Hello"
b = " World"
a = a + b
print a
But as I said Lets wait for masters' reply
M.S.
Junior Poster in Training
56 posts since Jul 2011
Reputation Points: 28
Solved Threads: 7
oh sorry I didnt noticed the space(" " instead of "") char in newMessage's default value.
I corrected it and its OK now.
M.S.
Junior Poster in Training
56 posts since Jul 2011
Reputation Points: 28
Solved Threads: 7
You are probably supposed to write out unicode characters not numbers in string format. See unichr function.
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852