def solve(self): cl = cherrypy.request.headers['Content-Length'] rawbody = cherrypy.request.body.read(int(cl)) body = simplejson.loads(rawbody) trie = Trie() trie.build_trie('wordsEn.txt') result = CodeBreaker.solve_code(body, trie, CodeAlphabet([[16, 'c']])) dictionary = {} for i in range(len(result.code_alphabet)): dictionary[i] = result.code_alphabet[i].letter return json.dumps(dictionary)
def solve(self): cl = cherrypy.request.headers["Content-Length"] rawbody = cherrypy.request.body.read(int(cl)) body = simplejson.loads(rawbody) trie = Trie() trie.build_trie("wordsEn.txt") result = CodeBreaker.solve_code(body, trie, CodeAlphabet([[16, "c"]])) dictionary = {} for i in range(len(result.code_alphabet)): dictionary[i] = result.code_alphabet[i].letter return json.dumps(dictionary)
code_table = [[19,14,22,17,21,22,16,11,-1,17,10,15, 6,26,22], [ 2,-1,20,-1, 3,-1, 2,-1, 2,-1,15,-1, 3,-1,13], [15, 2,18,22,20,-1, 7, 5, 3,26,17,-1,25,15,15], [24,-1, 3,-1,11,-1,17,-1,20,-1, 7,-1,25,-1, 2], [10, 3,14,11,-1, 1,24, 3,20,11,-1,14,22,20, 7], [-1,-1,22,-1,23,-1,-1,-1, 4,-1,-1,-1, 2,-1,13], [19,15, 2, 1,22,11, 7,20,-1, 1, 3, 7,13, 7,-1], [15,-1,-1,-1, 9,-1,20,-1,13,-1,20,-1,-1,-1, 7], [ 2,22, 6, 6,26,-1,24,10, 7, 2,22,17,26, 1,24], [12,-1,26,-1,20,-1,22,-1, 6,-1,19,-1,16,-1,10], [ 7, 8,24, 2, 7,12,26, 1,24,-1, 2,22, 4,15,20], [ 2,-1,-1,-1, 1,-1,14,-1,15,-1,22,-1,-1,-1,26], [-1,23,10,26, 1,11,-1,22, 2,24,26, 1,24,26,16], [ 1,-1,26,-1,-1,-1,14,-1,-1,-1,13,-1,10,-1,-1], [16, 3,14,24,-1,20,15,26, 1, 4,-1,26, 2,26, 1], [15,-1,14,-1,10,-1,24,-1,22,-1,24,-1,15,-1,14], [24,15,15,-1, 7, 5, 3,22,14,-1, 7, 8, 3,13, 7], [16,-1,16,-1,23,-1, 1,-1, 9,-1,20,-1,18,-1, 7], [10,26,11,26,20,18,-1,23,15,15,13,16,10,26,17]] trie = Trie() trie.build_trie('wordsEn.txt') #alphabet = '?sruyqbexvhkmdl?cpgfnjawtzi' #for index, letter in enumerate(alphabet): # if letter != '?': # code_alphabet = CodeAlphabet([[index,letter]]) # print(letter + ' ----- '+ str(CodeBreaker.solve_code(code_table, trie, code_alphabet))) print str(CodeBreaker.solve_code(code_table, trie, CodeAlphabet([[16, 'c']])))
[2, -1, 20, -1, 3, -1, 2, -1, 2, -1, 15, -1, 3, -1, 13], [15, 2, 18, 22, 20, -1, 7, 5, 3, 26, 17, -1, 25, 15, 15], [24, -1, 3, -1, 11, -1, 17, -1, 20, -1, 7, -1, 25, -1, 2], [10, 3, 14, 11, -1, 1, 24, 3, 20, 11, -1, 14, 22, 20, 7], [-1, -1, 22, -1, 23, -1, -1, -1, 4, -1, -1, -1, 2, -1, 13], [19, 15, 2, 1, 22, 11, 7, 20, -1, 1, 3, 7, 13, 7, -1], [15, -1, -1, -1, 9, -1, 20, -1, 13, -1, 20, -1, -1, -1, 7], [2, 22, 6, 6, 26, -1, 24, 10, 7, 2, 22, 17, 26, 1, 24], [12, -1, 26, -1, 20, -1, 22, -1, 6, -1, 19, -1, 16, -1, 10], [7, 8, 24, 2, 7, 12, 26, 1, 24, -1, 2, 22, 4, 15, 20], [2, -1, -1, -1, 1, -1, 14, -1, 15, -1, 22, -1, -1, -1, 26], [-1, 23, 10, 26, 1, 11, -1, 22, 2, 24, 26, 1, 24, 26, 16], [1, -1, 26, -1, -1, -1, 14, -1, -1, -1, 13, -1, 10, -1, -1], [16, 3, 14, 24, -1, 20, 15, 26, 1, 4, -1, 26, 2, 26, 1], [15, -1, 14, -1, 10, -1, 24, -1, 22, -1, 24, -1, 15, -1, 14], [24, 15, 15, -1, 7, 5, 3, 22, 14, -1, 7, 8, 3, 13, 7], [16, -1, 16, -1, 23, -1, 1, -1, 9, -1, 20, -1, 18, -1, 7], [10, 26, 11, 26, 20, 18, -1, 23, 15, 15, 13, 16, 10, 26, 17]] trie = Trie() trie.build_trie('wordsEn.txt') #alphabet = '?sruyqbexvhkmdl?cpgfnjawtzi' #for index, letter in enumerate(alphabet): # if letter != '?': # code_alphabet = CodeAlphabet([[index,letter]]) # print(letter + ' ----- '+ str(CodeBreaker.solve_code(code_table, trie, code_alphabet))) print str( CodeBreaker.solve_code(code_table, trie, CodeAlphabet([[16, 'c']])))