Snippets

stíobhart matulevicz CHHQ Puzzle Cracker

Created by stíobhart matulevicz
#coded message

message = (
'INA', 'AAA', 'IAN', 'INA', 'AAN', 'AIA', 'IAI', 'AIN',
'AAI', 'AAI', 'AII', 'AIA', 'AAA', 'IAA', 'INN', 'AAI',
'AAA', 'NNI', 'AIN', 'ANI', 'NAA', 'NNN', 'NMA', 'NAA',
'NIA', 'NMN', 'NNA', 'NNA', 'NNN', 'AMM', 'NNN', 'NAN',
'IMA', 'AIN', 'NIA', 'AMN', 'NAM', 'IAN', 'NAA', 'NIN',
'AMM', 'MIA', 'AMA', 'MMI', 'MAA', 'MMA', 'MMA', 'MAA',
'AMA', 'AMA', 'AAM', 'AAA', 'AMA', 'MAA', 'AAM', 'AMA',
'AIM', 'MMM', 'MMM', 'AMA'
)

#lined message—in case lines are significant
messageline01 = ("IN AAAAIAN INAAANAIA IA IAINA AI AA IAIIA IAA AAIAAINN AA IAAANN IAINANI")
messageline02 = ("NA ANNNNMA NAANIANMN NN ANNAN NN AM MNNNN ANI MAAINNIA AM NNAMIA NNAANIN")
messageline03 = ("AM MMIAAMA MMIMAAMMA MM AMAAA MA AM AAAMA AAA MAMAAAAM AM AAIMMM MMMMAMA")


#braille alphabet
braille = {
'A':'100000',
'B':'101000',
'C':'110000',
'D':'110100',
'E':'100100',
'F':'111000',
'G':'111100',
'H':'101100',
'I':'011000',
'J':'011100',
'K':'100010',
'L':'101010',
'M':'110010',
'N':'110110',
'O':'100110',
'P':'111010',
'Q':'111110',
'R':'101110',
'S':'011010',
'T':'011110',
'U':'100011',
'V':'101011',
'W':'011101',
'X':'110011',
'Y':'110111',
'Z':'100111'
}

#morse code
morse = {
'A':'10',
'I':'11',
'M':'00',
'N':'01',
}

#alternate morse code
altmorse = {
'A':'01',
'I':'00',
'M':'11',
'N':'10',
}


#try morse
print("\n===========================================================")
print("OPTION01 —MORSE")
print("===========================================================\n")
for section in message:
    #take 3 letters at a time and convert to morse
    #join 3 morse letters together to create braille letter
    brailleletter = (morse[section[0]]+morse[section[1]]+morse[section[2]])
    #lookup braille letter
    try:
        print((list(braille.keys())[list(braille.values()).index(brailleletter)]),end="")
    #if it doesn't exist, print '?'
    except:
        print("?",end="")
print("\n\n===========================================================\n")


#try alt morse
print("\n===========================================================")
print("OPTION02 —ALT MORSE")
print("===========================================================\n")
for section in message:
    #take 3 letters at a time and convert to morse
    #join 3 morse letters together to create braille letter
    altbrailleletter = (altmorse[section[0]]+altmorse[section[1]]+altmorse[section[2]])
    #lookup braille letter
    try:
        print((list(braille.keys())[list(braille.values()).index(altbrailleletter)]),end="")
    #if it doesn't exist, print '?'
    except:
        print("?",end="")
print("\n\n===========================================================\n")

#try building vertically
print("\n===========================================================")
print("OPTION03 —VERTICAL READING")
print("===========================================================\n")
vertmessage = []
for index in enumerate(messageline01):
    #print("index --> ",index[0])
    #take letters at a time from each line and group in threes
    brailleletter = (messageline01[index[0]]+messageline02[index[0]]+messageline03[index[0]])
    #print(brailleletter, end=" ")
    vertmessage.append(brailleletter)

print("vertical message = ",vertmessage)


print("\n===========================================================")
print("VERTICAL MESSAGE DECODING:")
print("===========================================================\n")
esperanto = ""
for section in vertmessage:
    #take 3 letters at a time and convert to morse
    #join 3 morse letters together to create braille letter
    #if the 'section' consists of 3 spaces, then interpret it s a single space between words'
    #yes. I know this is a bit clunky but it doesn't need regex!
    if section == "   ":
        esperanto += " "
    # 'section' wasn't a triple space, so look it up as a braille letter...
    # using the previous method
    else:
        brailleletter = (morse[section[0]]+morse[section[1]]+morse[section[2]])
    #lookup braille letter
        try:
            #if it exists, add it to the esperanto string
            esperanto += (list(braille.keys())[list(braille.values()).index(brailleletter)])
            #if it doesn't exist, print '?'
        except:
            esperanto += "?"
# print the constructed esperanto string
print(esperanto)
print("\n===========================================================\n")

Comments (0)