| self.params = None | self.params = None | ||||
| self.characters = None | self.characters = None | ||||
| self.art = None | self.art = None | ||||
| self.masterpassword = pw | |||||
| self.decode_key(pw) | self.decode_key(pw) | ||||
| else: | else: | ||||
| self.masterpassword = None | |||||
| self.create_campaign(n, makeChars) | self.create_campaign(n, makeChars) | ||||
| def create_campaign(self, n, makeChars): | def create_campaign(self, n, makeChars): | ||||
| "gadget": bin(chct.gadget["id"])[2:] | "gadget": bin(chct.gadget["id"])[2:] | ||||
| } | } | ||||
| i += 1 | i += 1 | ||||
| # print(chars) | |||||
| l1 = lpad(l1, 7) | l1 = lpad(l1, 7) | ||||
| # print(f"Len(l1) = {len(l1)}") | |||||
| l2 = lpad(l2, 7) | l2 = lpad(l2, 7) | ||||
| # print(f"Len(l2) = {len(l2)}") | |||||
| ms = lpad(ms, 7) | ms = lpad(ms, 7) | ||||
| # print(f"Len(ms) = {len(ms)}") | |||||
| pb1 = lpad(pb1, 7) | pb1 = lpad(pb1, 7) | ||||
| # print(f"Len(pb1) = {len(pb1)}") | |||||
| pb2 = lpad(pb2, 7) | pb2 = lpad(pb2, 7) | ||||
| # print(f"Len(pb2) = {len(pb2)}") | |||||
| pbname = lpad(pbname, 40, "1") | pbname = lpad(pbname, 40, "1") | ||||
| # print(f"Len(pbname) = {len(pbname)}") | |||||
| n1 = lpad(n1, 7) | n1 = lpad(n1, 7) | ||||
| # print(f"Len(n1) = {len(n1)}") | |||||
| n2 = lpad(n2, 7) | n2 = lpad(n2, 7) | ||||
| # print(f"Len(n2) = {len(n2)}") | |||||
| gq = lpad(gq, 7) | gq = lpad(gq, 7) | ||||
| # print(f"Len(gq) = {len(gq)}") | |||||
| bq = lpad(bq, 7) | bq = lpad(bq, 7) | ||||
| # print(f"Len(bq) = {len(bq)}") | |||||
| self.key += l1 + l2 + lb + op + ms + pb1 + pbname + pb2 + n1 + n2 + gq + bq | self.key += l1 + l2 + lb + op + ms + pb1 + pbname + pb2 + n1 + n2 + gq + bq | ||||
| for k,chct in chars.items(): | for k,chct in chars.items(): | ||||
| chct["name"] = lpad(chct["name"], 40, "1") | chct["name"] = lpad(chct["name"], 40, "1") | ||||
| # print(f"Len(chct.name) = {len(chct['name'])}") | |||||
| chct["career"] = lpad(chct["career"], 7) | chct["career"] = lpad(chct["career"], 7) | ||||
| # print(f"Len(chct.career) = {len(chct['career'])}") | |||||
| chct["order"] = lpad(chct["order"],3) | chct["order"] = lpad(chct["order"],3) | ||||
| # print(f"Len(chct.order) = {len(chct['order'])}") | |||||
| chct["chaos"] = lpad(chct["chaos"], 3) | chct["chaos"] = lpad(chct["chaos"], 3) | ||||
| # print(f"Len(chct.chaos) = {len(chct['chaos'])}") | |||||
| chct["body"] = lpad(chct["body"], 3) | chct["body"] = lpad(chct["body"], 3) | ||||
| # print(f"Len(chct.body) = {len(chct['body'])}") | |||||
| chct["brains"] = lpad(chct["brains"], 3) | chct["brains"] = lpad(chct["brains"], 3) | ||||
| # print(f"Len(chct.brains) = {len(chct['brains'])}") | |||||
| chct["gadget"] = lpad(chct["gadget"], 7) | chct["gadget"] = lpad(chct["gadget"], 7) | ||||
| # print(f"Len(chct.gadget) = {len(chct['gadget'])}") | |||||
| self.key += chct["name"] + chct["career"] + chct["order"] + chct["chaos"] + chct["body"] + chct["brains"] + chct["gadget"] | self.key += chct["name"] + chct["career"] + chct["order"] + chct["chaos"] + chct["body"] + chct["brains"] + chct["gadget"] | ||||
| # print(len(self.key)) | |||||
| while len(self.key) < 509: | while len(self.key) < 509: | ||||
| self.key = self.key + "0" | self.key = self.key + "0" | ||||
| # print(len(self.key)) | |||||
| print(self.key) | |||||
| self.okey = "" | self.okey = "" | ||||
| letters = [] | letters = [] | ||||
| letter = [] | letter = [] | ||||
| word = [] | word = [] | ||||
| words.append("".join(word)) | words.append("".join(word)) | ||||
| self.password = " ".join(words) | self.password = " ".join(words) | ||||
| # print(self.password) | |||||
| return self.password | return self.password | ||||
| def decode_key(self, pw): | def decode_key(self, pw): | ||||
| # Character 6 gadget: 7 bits | # Character 6 gadget: 7 bits | ||||
| i,j = j,j+7 | i,j = j,j+7 | ||||
| outkey["char6gad"] = int(self.newBitfield[i:j], 2) | outkey["char6gad"] = int(self.newBitfield[i:j], 2) | ||||
| #print(self.newBitfield) | |||||
| #print(outkey) | |||||
| self.ship = Ship(Ship.NAME1[outkey["sname1"]], Ship.NAME2[outkey["sname2"]], Ship.GQUAL[outkey["gqual"]], Ship.BQUAL[outkey["bqual"]]) | self.ship = Ship(Ship.NAME1[outkey["sname1"]], Ship.NAME2[outkey["sname2"]], Ship.GQUAL[outkey["gqual"]], Ship.BQUAL[outkey["bqual"]]) | ||||
| self.params = Plot(loc_desc=Plot.loc1[outkey["loc1"]], locIndex=outkey["loc2"], battlefield=outkey["battlefield"], location=None, missIndex=outkey["miss"], oops=outkey["oops"], mission=None, probIndex=outkey["prob1"], problem=None, probName=self.decode_name(outkey["prob1name"]), secProblem=outkey["prob2"], thirdProblem=None) | self.params = Plot(loc_desc=Plot.loc1[outkey["loc1"]], locIndex=outkey["loc2"], battlefield=outkey["battlefield"], location=None, missIndex=outkey["miss"], oops=outkey["oops"], mission=None, probIndex=outkey["prob1"], problem=None, probName=self.decode_name(outkey["prob1name"]), secProblem=outkey["prob2"], thirdProblem=None) | ||||
| self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a" | self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a" | ||||
| keys = [f"char{q}name", f"char{q}career", f"char{q}ord", f"char{q}cha", f"char{q}bod", f"char{q}bra", f"char{q}gad"] | keys = [f"char{q}name", f"char{q}career", f"char{q}ord", f"char{q}cha", f"char{q}bod", f"char{q}bra", f"char{q}gad"] | ||||
| c = Character(name=self.decode_name(outkey[keys[0]]), career=outkey[keys[1]], stats=[outkey[keys[2]], outkey[keys[3]], outkey[keys[4]], outkey[keys[5]]], gadget=outkey[keys[6]]) | c = Character(name=self.decode_name(outkey[keys[0]]), career=outkey[keys[1]], stats=[outkey[keys[2]], outkey[keys[3]], outkey[keys[4]], outkey[keys[5]]], gadget=outkey[keys[6]]) | ||||
| self.characters.append(c) | self.characters.append(c) | ||||
| #self.ship.print() | |||||
| # self.print_params() | |||||
| # self.print_chars() | |||||
| return self.newBitfield | |||||
| #return self.newBitfield | |||||
| def encode_name(self, name): | def encode_name(self, name): | ||||
| field = "".join([lpad(bin(Campaign.NAMELETS.index(c.lower()))[2:], 5) for c in name]) | field = "".join([lpad(bin(Campaign.NAMELETS.index(c.lower()))[2:], 5) for c in name]) | ||||
| return name | return name | ||||
| def print_params(self, endc=" ", html=False): | def print_params(self, endc=" ", html=False): | ||||
| # print(len(Plot.miss)) | |||||
| st = ["Order:", "Chaos:", "Brains:", "Body:"] | st = ["Order:", "Chaos:", "Brains:", "Body:"] | ||||
| cst = ", ".join([" ".join(y) for y in list(zip(st, [str(x) for x in self.params.problem["stats"]]))]) | cst = ", ".join([" ".join(y) for y in list(zip(st, [str(x) for x in self.params.problem["stats"]]))]) | ||||
| if self.params.oops == 1: | if self.params.oops == 1: | ||||
| print(f"</div>\n<br clear='all'>\n") | print(f"</div>\n<br clear='all'>\n") | ||||
| def print_password(self, html=False): | def print_password(self, html=False): | ||||
| pw = self.generate_key() | |||||
| if self.masterpassword: | |||||
| pw = self.masterpassword | |||||
| else: | |||||
| pw = self.generate_key() | |||||
| if html: | if html: | ||||
| out = ( | out = ( | ||||
| f"<div id='password'>" | f"<div id='password'>" | ||||
| f"</div>" | f"</div>" | ||||
| ) | ) | ||||
| print(out) | print(out) | ||||
| print(f"<br clear='all'>\n") | |||||
| else: | else: | ||||
| print(f"Password: {pw}") | print(f"Password: {pw}") | ||||
| def decode(self, pwd): | def decode(self, pwd): | ||||
| pass | pass | ||||
| class Password: | |||||
| pass | |||||
| def lpad(s, n, c="0"): | def lpad(s, n, c="0"): | ||||
| while len(s) < n: | while len(s) < n: | ||||
| s = c + s | s = c + s | ||||
| group.add_argument("-pw", "--password", help="print the campaign defined by the submitted password", type=str, nargs="?", const=1, metavar="PW") | group.add_argument("-pw", "--password", help="print the campaign defined by the submitted password", type=str, nargs="?", const=1, metavar="PW") | ||||
| parser.add_argument("--html", help="print in HTML instead of plain text", action="store_true") | parser.add_argument("--html", help="print in HTML instead of plain text", action="store_true") | ||||
| args = parser.parse_args() | args = parser.parse_args() | ||||
| # print(args) | |||||
| html = True if args.html else False | html = True if args.html else False | ||||
| if args.password: | if args.password: | ||||
| #pw = Password(args.password) | |||||
| # print(pw.newBitfield) | |||||
| cmp = Campaign(fromPW = True, pw=args.password) | cmp = Campaign(fromPW = True, pw=args.password) | ||||
| cmp.print_params(html=html) | cmp.print_params(html=html) | ||||
| cmp.print_chars(html=html) | cmp.print_chars(html=html) |