Jun-09-2020, 01:43 AM
I decided to write a text to binary translator only using math. This was to test my abilities because I am very new. This can only translate letters and nothing else. I knew how to do binary in my head, so I made a program without using a dictionary to simply match.
def Binary(phrase): ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" def Find(letter): Count = 0 for LETTER in ALPHABET: Count += 1 if letter.upper() == LETTER: return Count break result = "" for letter in phrase: try: output = "" value = 0 if letter.upper() in ALPHABET: if letter.upper() == letter: value += 1000000 spot = Find(letter) if spot >= 16: value += 10000 spot -= 16 if spot >= 8: value += 1000 spot -= 8 if spot >= 4: value += 100 spot -= 4 if spot >= 2: value += 10 spot -= 2 if spot >= 1: value += 1 spot -= 1 output += str(value) elif letter.lower() == letter: value += 1100000 spot = Find(letter) if spot >= 16: value += 10000 spot -= 16 if spot >= 8: value += 1000 spot -= 8 if spot >= 4: value += 100 spot -= 4 if spot >= 2: value += 10 spot -= 2 if spot >= 1: value += 1 spot -= 1 output += str(value) result += "0" + output + " " else: result += "00100000 " except: pass return result