class Header(object): format = struct.Struct("!QQQQQQ") size = len(checksum().digest()) + format.size @classmethod def unpack(cls, data): digest = data[cls.format.size:] if digest != checksum(data[:cls.format.size]).digest(): raise HeaderError("header data does not match the checksum") unpacked = cls.format.unpack(data[:cls.format.size]) return cls(*unpacked) def __init__(self, last_commit, count, last, tail, open_head, open_tail): self.last_commit = last_commit self.count = count self.last = last self.tail = tail self.open_head = open_head self.open_tail = open_tail def pack(self): data = self.format.pack(self.last_commit, self.count, self.last, self.tail, self.open_head, self.open_tail) return data + checksum(data).digest()
def validate(data): sh = data.pop() if checksum(str(data)).hexdigest() == sh: return True else: return False
try: scheduled = int(now()) seat(scheduled) rc = RC4(KEY) ticket = rc.decrypt(raw_input(welcome(scheduled))) if "invalid" in ticket: free = raw_input(" Wanna Free Ticket? [y/N] ") if free.lower() == "y": data = ["free", "guest"] data.append(str(scheduled + 60)) else: data = ["book"] data.append(raw_input(" Booking NOW!!!\n Name: ")) data.append(str(scheduled + 60**2 * 4 * 4)) data.append(checksum(str(data)).hexdigest()) print " Your Ticket:", rc.encrypt(data), else: if ticket[0] == "flag": flag = FLAG elif ticket[0] == "book": if validate(ticket) and "flag" in ticket: if int(now()) > int(ticket[2]): flag = FLAG else: flag = "ToO SoOn" else: flag = ticket[1] else: flag = "" congrat(flag)
def pack(self): data = self.format.pack(self.last_commit, self.count, self.last, self.tail, self.open_head, self.open_tail) return data + checksum(data).digest()
def unpack(cls, data): digest = data[cls.format.size:] if digest != checksum(data[:cls.format.size]).digest(): raise HeaderError("header data does not match the checksum") unpacked = cls.format.unpack(data[:cls.format.size]) return cls(*unpacked)