Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Hacker Language by marcopunteri
import string, re
class HackerLanguage:
translation_dict = {a : "{0:b}".format(ord(a)) for a in string.ascii_letters}
translation_dict.update({' ': '1000000'})
translation_table = str.maketrans(translation_dict)
def __init__(self):
self.text = ''
def write(self,txt):
self.text += txt
def delete(self,N):
self.text = self.text[:-N]
def send(self):
return self.text.translate(self.translation_table)
def read(self,text):
output_text = ''
while text:
chunk = text[:7]
if len([l for l in chunk if l in ("0","1")]) == 7:
chunk = "100000" if chunk == "1000000" else chunk
output_text += chr(int(chunk,2))
text = text[7:]
else:
output_text += text[0]
text = text[1:]
return output_text
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
message_1 = HackerLanguage()
message_1.write("secrit")
message_1.delete(2)
message_1.write("et")
message_2 = HackerLanguage()
assert message_1.send() == "111001111001011100011111001011001011110100"
assert message_2.read("11001011101101110000111010011101100") == "email"
print("Coding complete? Let's try tests!")
Aug. 2, 2021
Comments: