#!/usr/bin/env python import sys def cmap(x): if x=="0": return 0x0 if x=="1": return 0x1 if x=="2": return 0x2 if x=="3": return 0x3 if x=="4": return 0x4 if x=="5": return 0x5 if x=="6": return 0x6 if x=="7": return 0x7 if x=="8": return 0x8 if x=="9": return 0x9 if x=="a": return 0xa if x=="b": return 0xb if x=="c": return 0xc if x=="d": return 0xd if x=="e": return 0xe if x=="f": return 0xf if x=="A": return 0xa if x=="B": return 0xb if x=="C": return 0xc if x=="D": return 0xd if x=="E": return 0xe if x=="F": return 0xf print "Invalid service tag" sys.exit(0) def str2num(x): out = 0 while(len(x) > 0): q = cmap(x[0]) x = x[1:] if(len(x) == 0): return out | q out |= q out <<= 4 print "Invalid service tag" sys.exit(0) # Quick and dirty 2-bit "party" of hex number def a91a15d7(x): # a and b are 2-bit inputs for the s-box # s is a 32-bit representation of this s-box def sbox(a,b,s): a &= 3 b &= 3 index = (a | (b << 2)) out = s out >>= (index * 2) out &= 3 return out if x < 0: return -1 # ERROR out = 0 index = 0 while(x > 0): q = (x & 3) s = sbox(q,index,0xa91a15d7) # From RadioGatun[32] of "parity" out += s out ^= q out &= 3 index += 1 index &= 3 x >>= 2 return out & 3 try: serviceString = sys.argv[1] except: print "Usage: service.tag {service tag}" sys.exit(0) s = str2num(serviceString) rotate = (s >> 83) & 1 sealevel = (s >> 81) & 3 climate = (s >> 78) & 7 new_world = (s >> 77) & 1 pangeas = (s >> 76) & 1 mountains = (s >> 75) & 1 patience = (s >> 73) & 3 ratio = (s >> 70) & 7 islands = (s >> 68) & 3 wrap = (s >> 66) & 3 height = (s >> 60) & 63 handicap = (s >> 58) & 3 same_land = (s >> 57) & 1 resources = (s >> 55) & 3 sum = (s >> 53) & 3 seed = (s & 0x1fffffffffffff) sum_verify = a91a15d7(s & 0xfffffff9fffffffffffff) print "rotate: %x" % (rotate) print "sealevel: %x" % (sealevel) print "climate: %x" % (climate) print "new_world: %x" % (new_world) print "pangeas: %x" % (pangeas) print "mountains: %x" % (mountains) print "patience: %x" % (patience) print "ratio: %x" % (ratio) print "islands: %x" % (islands) print "wrap: %x" % (wrap) print "height: %x" % (height) print "handicap: %x" % (handicap) print "same_land: %x" % (same_land) print "resources: %x" % (resources) print "sum: %x" % (sum) print "sum_verify: %x" % (sum_verify) print "seed: %x" % (seed)