text: #!/usr/bin/python3
  
  # Project     : pyzrtp
  # Copyright (C) 2017 Orange
  # All rights reserved.
  # This software is distributed under the terms and conditions of the 'BSD 3-Clause'
  # license which can be found in the file 'LICENSE' in this package distribution.
  
  from struct import unpack
  
  class UnsupportedSASType(Exception): pass
  
  def b256(sas):
    assert(len(sas) == 4)
    words = [('aardvark', 'adroitness'), ('absurd', 'adviser'), ('accrue', 'aftermath'), ('acme', 'aggregate'), ('adrift', 'alkali'), ('adult', 'almighty'), ('afflict', 'amulet'), ('ahead', 'amusement'), ('aimless', 'antenna'), ('Algol', 'applicant'), ('allow', 'Apollo'), ('alone', 'armistice'), ('ammo', 'article'), ('ancient', 'asteroid'), ('apple', 'Atlantic'), ('artist', 'atmosphere'), ('assume', 'autopsy'), ('Athens', 'Babylon'), ('atlas', 'backwater'), ('Aztec', 'barbecue'), ('baboon', 'belowground'), ('backfield', 'bifocals'), ('backward', 'bodyguard'), ('banjo', 'bookseller'), ('beaming', 'borderline'), ('bedlamp', 'bottomless'), ('beehive', 'Bradbury'), ('beeswax', 'bravado'), ('befriend', 'Brazilian'), ('Belfast', 'breakaway'), ('berserk', 'Burlington'), ('billiard', 'businessman'), ('bison', 'butterfat'), ('blackjack', 'Camelot'), ('blockade', 'candidate'), ('blowtorch', 'cannonball'), ('bluebird', 'Capricorn'), ('bombast', 'caravan'), ('bookshelf', 'caretaker'), ('brackish', 'celebrate'), ('breadline', 'cellulose'), ('breakup', 'certify'), ('brickyard', 'chambermaid'), ('briefcase', 'Cherokee'), ('Burbank', 'Chicago'), ('button', 'clergyman'), ('buzzard', 'coherence'), ('cement', 'combustion'), ('chairlift', 'commando'), ('chatter', 'company'), ('checkup', 'component'), ('chisel', 'concurrent'), ('choking', 'confidence'), ('chopper', 'conformist'), ('Christmas', 'congregate'), ('clamshell', 'consensus'), ('classic', 'consulting'), ('classroom', 'corporate'), ('cleanup', 'corrosion'), ('clockwork', 'councilman'), ('cobra', 'crossover'), ('commence', 'crucifix'), ('concert', 'cumbersome'), ('cowbell', 'customer'), ('crackdown', 'Dakota'), ('cranky', 'decadence'), ('crowfoot', 'December'), ('crucial', 'decimal'), ('crumpled', 'designing'), ('crusade', 'detector'), ('cubic', 'detergent'), ('dashboard', 'determine'), ('deadbolt', 'dictator'), ('deckhand', 'dinosaur'), ('dogsled', 'direction'), ('dragnet', 'disable'), ('drainage', 'disbelief'), ('dreadful', 'disruptive'), ('drifter', 'distortion'), ('dropper', 'document'), ('drumbeat', 'embezzle'), ('drunken', 'enchanting'), ('Dupont', 'enrollment'), ('dwelling', 'enterprise'), ('eating', 'equation'), ('edict', 'equipment'), ('egghead', 'escapade'), ('eightball', 'Eskimo'), ('endorse', 'everyday'), ('endow', 'examine'), ('enlist', 'existence'), ('erase', 'exodus'), ('escape', 'fascinate'), ('exceed', 'filament'), ('eyeglass', 'finicky'), ('eyetooth', 'forever'), ('facial', 'fortitude'), ('fallout', 'frequency'), ('flagpole', 'gadgetry'), ('flatfoot', 'Galveston'), ('flytrap', 'getaway'), ('fracture', 'glossary'), ('framework', 'gossamer'), ('freedom', 'graduate'), ('frighten', 'gravity'), ('gazelle', 'guitarist'), ('Geiger', 'hamburger'), ('glitter', 'Hamilton'), ('glucose', 'handiwork'), ('goggles', 'hazardous'), ('goldfish', 'headwaters'), ('gremlin', 'hemisphere'), ('guidance', 'hesitate'), ('hamlet', 'hideaway'), ('highchair', 'holiness'), ('hockey', 'hurricane'), ('indoors', 'hydraulic'), ('indulge', 'impartial'), ('inverse', 'impetus'), ('involve', 'inception'), ('island', 'indigo'), ('jawbone', 'inertia'), ('keyboard', 'infancy'), ('kickoff', 'inferno'), ('kiwi', 'informant'), ('klaxon', 'insincere'), ('locale', 'insurgent'), ('lockup', 'integrate'), ('merit', 'intention'), ('minnow', 'inventive'), ('miser', 'Istanbul'), ('Mohawk', 'Jamaica'), ('mural', 'Jupiter'), ('music', 'leprosy'), ('necklace', 'letterhead'), ('Neptune', 'liberty'), ('newborn', 'maritime'), ('nightbird', 'matchmaker'), ('Oakland', 'maverick'), ('obtuse', 'Medusa'), ('offload', 'megaton'), ('optic', 'microscope'), ('orca', 'microwave'), ('payday', 'midsummer'), ('peachy', 'millionaire'), ('pheasant', 'miracle'), ('physique', 'misnomer'), ('playhouse', 'molasses'), ('Pluto', 'molecule'), ('preclude', 'Montana'), ('prefer', 'monument'), ('preshrunk', 'mosquito'), ('printer', 'narrative'), ('prowler', 'nebula'), ('pupil', 'newsletter'), ('puppy', 'Norwegian'), ('python', 'October'), ('quadrant', 'Ohio'), ('quiver', 'onlooker'), ('quota', 'opulent'), ('ragtime', 'Orlando'), ('ratchet', 'outfielder'), ('rebirth', 'Pacific'), ('reform', 'pandemic'), ('regain', 'Pandora'), ('reindeer', 'paperweight'), ('rematch', 'paragon'), ('repay', 'paragraph'), ('retouch', 'paramount'), ('revenge', 'passenger'), ('reward', 'pedigree'), ('rhythm', 'Pegasus'), ('ribcage', 'penetrate'), ('ringbolt', 'perceptive'), ('robust', 'performance'), ('rocker', 'pharmacy'), ('ruffled', 'phonetic'), ('sailboat', 'photograph'), ('sawdust', 'pioneer'), ('scallion', 'pocketful'), ('scenic', 'politeness'), ('scorecard', 'positive'), ('Scotland', 'potato'), ('seabird', 'processor'), ('select', 'provincial'), ('sentence', 'proximate'), ('shadow', 'puberty'), ('shamrock', 'publisher'), ('showgirl', 'pyramid'), ('skullcap', 'quantity'), ('skydive', 'racketeer'), ('slingshot', 'rebellion'), ('slowdown', 'recipe'), ('snapline', 'recover'), ('snapshot', 'repellent'), ('snowcap', 'replica'), ('snowslide', 'reproduce'), ('solo', 'resistor'), ('southward', 'responsive'), ('soybean', 'retraction'), ('spaniel', 'retrieval'), ('spearhead', 'retrospect'), ('spellbind', 'revenue'), ('spheroid', 'revival'), ('spigot', 'revolver'), ('spindle', 'sandalwood'), ('spyglass', 'sardonic'), ('stagehand', 'Saturday'), ('stagnate', 'savagery'), ('stairway', 'scavenger'), ('standard', 'sensation'), ('stapler', 'sociable'), ('steamship', 'souvenir'), ('sterling', 'specialist'), ('stockman', 'speculate'), ('stopwatch', 'stethoscope'), ('stormy', 'stupendous'), ('sugar', 'supportive'), ('surmount', 'surrender'), ('suspense', 'suspicious'), ('sweatband', 'sympathy'), ('swelter', 'tambourine'), ('tactics', 'telephone'), ('talon', 'therapist'), ('tapeworm', 'tobacco'), ('tempest', 'tolerance'), ('tiger', 'tomorrow'), ('tissue', 'torpedo'), ('tonic', 'tradition'), ('topmost', 'travesty'), ('tracker', 'trombonist'), ('transit', 'truncated'), ('trauma', 'typewriter'), ('treadmill', 'ultimate'), ('Trojan', 'undaunted'), ('trouble', 'underfoot'), ('tumor', 'unicorn'), ('tunnel', 'unify'), ('tycoon', 'universe'), ('uncut', 'unravel'), ('unearth', 'upcoming'), ('unwind', 'vacancy'), ('uproot', 'vagabond'), ('upset', 'vertigo'), ('upshot', 'Virginia'), ('vapor', 'visitor'), ('village', 'vocalist'), ('virus', 'voyager'), ('Vulcan', 'warranty'), ('waffle', 'Waterloo'), ('wallet', 'whimsical'), ('watchword', 'Wichita'), ('wayside', 'Wilmington'), ('willow', 'Wyoming'), ('woodlark', 'yesteryear'), ('Zulu', 'Yucatan')]
    return '%s:%s' % (words[sas[0]][0], words[sas[1]][1])
  
  def b32(sas):
    assert(len(sas) == 4)
    u32 = unpack('!I', sas)[0]
  
    result = ''
  
    shift = 27
    for i in range(0, 4):
      n = (u32>>shift) & 31
      result += 'ybndrfg8ejkmcpqxot1uwisza345h769'[n]
      shift -= 5
  
    return result
  
  SASS = (
    (b'B32 ', b32), # 
    (b'B256', b256), # 
    (b'B32E', ), # 
  )
  
  def get(name):
    sas = None
    for (sname, constructor) in SASS:
      if sname == name: return constructor
    if sas is None: raise UnsupportedSASType(name)
  
  if __name__ == '__main__':
    def sas(name):
      return get(name)
  
    assert(sas(b'B256')(b'\x53\x3c\x50\x00') == 'dwelling:crossover')
    assert(sas(b'B256')(b'\xed\xfc\x00\x00') == 'tunnel:Wilmington')
  
    assert(sas(b'B32 ')(b'\x2a\xf2\xb0\x00') == 'fm3m')
    assert(sas(b'B32 ')(b'\xde\xfa\x40\x00') == '557r')
  