0

Why is the encrypt function outputing the memory location?

here is the code: from math import sqrt class Code(): def __init__(self, text, key, t): self.text = text self.key = key if t == "E": self.encrypt(self.text, self.key) elif t == "D": self.decrypt(self.text, self.key) def encrypt(self, text, key): words = text.split(" ") letters = [] encrypted_msg = [] for word in words: letters.append(list(word)) for list1 in letters: for letter in list1: encrypted_msg.append((ord(letter)**2) + ord(key)) return encrypted_msg def decrypt(self, msg, key): int_words = " " for number in msg: int_words += str(chr(int(sqrt(number - ord(key))))) return int_words text = input("Input message:: ") print ("........................................................") print ("encrypting message") print ("........................................................") E_message = Code(text, "w", "E") print (E_message) print ("........................................................") print ("decrypting message") print ("....................

5th Jun 2018, 8:09 AM
Kyle Matthew Ford
Kyle Matthew Ford - avatar
3 Respostas
+ 2
The problem is here. E_message = Code(text, "w", "E") This line creates Code class instance and the instance is saved to the E_message. So this code shows the memory address of the object of Code.
5th Jun 2018, 8:29 AM
Disvolviĝo;
Disvolviĝo; - avatar
+ 1
Because your are printing a Code object that for default print his type and memory location... You want print the result of encrypt (and decrypt) function then you have not to do they in constructor and you have to edit ctor to store the key and encrypt/decrypt function for accept plain/encrypted text: codeObj= Code(key) encText= codeObj.encrypt(text) plain= codeObj.decrypt(encText)
5th Jun 2018, 8:30 AM
KrOW
KrOW - avatar
+ 1
Oh! Thanks guys....it makes sense now.
5th Jun 2018, 8:35 AM
Kyle Matthew Ford
Kyle Matthew Ford - avatar