Decode PC23 Message which usually contains WCY
770183
def decode_pc23_message(raw_string):
    

    data = {}
    wcy = raw_string.split("^")
    data[const.R] = int(wcy[1])
    data[const.expk] = int(wcy[2])
    data[const.CALLSIGN] = wcy[3]
    data[const.A] = wcy[4]
    data[const.SFI] = wcy[5]
    data[const.K] = wcy[6]
    data[const.AURORA] = wcy[7]
    data["node"] = wcy[7]
    data["ip"] = wcy[8]
    data["raw_data"] = raw_string
    return data
388737
def _decode(self):
        

        s = self._encoded_value
        elements = s.replace('~', '').split('!')
        dec_elements = []

        for elem in elements:
            result = []
            idx = 0
            while (idx < len(elem)):
                # Get the idx'th character of s
                c = elem[idx]

                if (c in CPEComponent1_1.NON_STANDARD_VALUES):
                    # Escape character
                    result.append("\\")
                    result.append(c)
                else:
                    # Do nothing
                    result.append(c)

                idx += 1
            dec_elements.append("".join(result))

        self._standard_value = dec_elements
547935
def decode_qwikcord(packet, channel=1):
    """"""
    val = str(packet.get('val', ''))
    if len(val) != 16:
        return None
    if channel == 1:
        return int(val[6:12], 16)  # CTavg
    return int(val[12:], 16)
373663
def ws45(msg):
    
    d = hex2bin(data(msg))
    if d[3] == '0':
        return None

    ws = bin2int(d[4:6])
    return ws
1035659
def decode_packet(data):
    """"""
    if _debug: decode_packet._debug("decode_packet %r", data)

    # empty strings are some other kind of pcap content
    if not data:
        return None

    # assume it is ethernet for now
    d = decode_ethernet(data)
    pduSource = Address(d['source_address'])
    pduDestination = Address(d['destination_address'])
    data = d['data']

    # there could be a VLAN header
    if (d['type'] == 0x8100):
        if _debug: decode_packet._debug("    - vlan found")

        d = decode_vlan(data)
        data = d['data']

    # look for IP packets
    if (d['type'] == 0x0800):
        if _debug: decode_packet._debug("    - IP found")

        d = decode_ip(data)
        pduSource, pduDestination = d['source_address'], d['destination_address']
        data = d['data']

        if (d['protocol'] == 'udp'):
            if _debug: decode_packet._debug("    - UDP found")

            d = decode_udp(data)
            data = d['data']

            pduSource = Address((pduSource, d['source_port']))
            pduDestination = Address((pduDestination, d['destination_port']))
            if _debug:
                decode_packet._debug("    - pduSource: %r", pduSource)
                decode_packet._debug("    - pduDestination: %r", pduDestination)
        else:
            if _debug: decode_packet._debug("    - not a UDP packet")
    else:
        if _debug: decode_packet._debug("    - not an IP packet")

    # check for empty
    if not data:
        if _debug: decode_packet._debug("    - empty packet")
        return None

    # build a PDU
    pdu = PDU(data, source=pduSource, destination=pduDestination)

    # check for a BVLL header
    if (pdu.pduData[0] == 0x81):
        if _debug: decode_packet._debug("    - BVLL header found")

        try:
            xpdu = BVLPDU()
            xpdu.decode(pdu)
            pdu = xpdu
        except Exception as err:
            if _debug: decode_packet._debug("    - BVLPDU decoding error: %r", err)
            return pdu

        # make a more focused interpretation
        atype = bvl_pdu_types.get(pdu.bvlciFunction)
        if not atype:
            if _debug: decode_packet._debug("    - unknown BVLL type: %r", pdu.bvlciFunction)
            return pdu

        # decode it as one of the basic types
        try:
            xpdu = pdu
            bpdu = atype()
            bpdu.decode(pdu)
            if _debug: decode_packet._debug("    - bpdu: %r", bpdu)

            pdu = bpdu

            # lift the address for forwarded NPDU's
            if atype is ForwardedNPDU:
                pdu.pduSource = bpdu.bvlciAddress
            # no deeper decoding for some
            elif atype not in (DistributeBroadcastToNetwork, OriginalUnicastNPDU, OriginalBroadcastNPDU):
                return pdu

        except Exception as err:
            if _debug: decode_packet._debug("    - decoding Error: %r", err)
            return xpdu

    # check for version number
    if (pdu.pduData[0] != 0x01):
        if _debug: decode_packet._debug("    - not a version 1 packet: %s...", btox(pdu.pduData[:30], '.'))
        return None

    # it's an NPDU
    try:
        npdu = NPDU()
        npdu.decode(pdu)
    except Exception as err:
        if _debug: decode_packet._debug("    - decoding Error: %r", err)
        return None

    # application or network layer message
    if npdu.npduNetMessage is None:
        if _debug: decode_packet._debug("    - not a network layer message, try as an APDU")

        # decode as a generic APDU
        try:
            xpdu = APDU()
            xpdu.decode(npdu)
            apdu = xpdu
        except Exception as err:
            if _debug: decode_packet._debug("    - decoding Error: %r", err)
            return npdu

        # "lift" the source and destination address
        if npdu.npduSADR:
            apdu.pduSource = npdu.npduSADR
        else:
            apdu.pduSource = npdu.pduSource
        if npdu.npduDADR:
            apdu.pduDestination = npdu.npduDADR
        else:
            apdu.pduDestination = npdu.pduDestination

        # make a more focused interpretation
        atype = apdu_types.get(apdu.apduType)
        if not atype:
            if _debug: decode_packet._debug("    - unknown APDU type: %r", apdu.apduType)
            return apdu

        # decode it as one of the basic types
        try:
            xpdu = apdu
            apdu = atype()
            apdu.decode(xpdu)
        except Exception as err:
            if _debug: decode_packet._debug("    - decoding Error: %r", err)
            return xpdu

        # decode it at the next level
        if isinstance(apdu, ConfirmedRequestPDU):
            atype = confirmed_request_types.get(apdu.apduService)
            if not atype:
                if _debug: decode_packet._debug("    - no confirmed request decoder: %r", apdu.apduService)
                return apdu

        elif isinstance(apdu, UnconfirmedRequestPDU):
            atype = unconfirmed_request_types.get(apdu.apduService)
            if not atype:
                if _debug: decode_packet._debug("    - no unconfirmed request decoder: %r", apdu.apduService)
                return apdu

        elif isinstance(apdu, SimpleAckPDU):
            atype = None

        elif isinstance(apdu, ComplexAckPDU):
            atype = complex_ack_types.get(apdu.apduService)
            if not atype:
                if _debug: decode_packet._debug("    - no complex ack decoder: %r", apdu.apduService)
                return apdu

        elif isinstance(apdu, SegmentAckPDU):
            atype = None

        elif isinstance(apdu, ErrorPDU):
            atype = error_types.get(apdu.apduService)
            if not atype:
                if _debug: decode_packet._debug("    - no error decoder: %r", apdu.apduService)
                return apdu

        elif isinstance(apdu, RejectPDU):
            atype = None

        elif isinstance(apdu, AbortPDU):
            atype = None
        if _debug: decode_packet._debug("    - atype: %r", atype)

        # deeper decoding
        try:
            if atype:
                xpdu = apdu
                apdu = atype()
                apdu.decode(xpdu)
        except Exception as err:
            if _debug: decode_packet._debug("    - decoding error: %r", err)
            return xpdu

        # success
        return apdu

    else:
        # make a more focused interpretation
        ntype = npdu_types.get(npdu.npduNetMessage)
        if not ntype:
            if _debug: decode_packet._debug("    - no network layer decoder: %r", npdu.npduNetMessage)
            return npdu
        if _debug: decode_packet._debug("    - ntype: %r", ntype)

        # deeper decoding
        try:
            xpdu = npdu
            npdu = ntype()
            npdu.decode(xpdu)
        except Exception as err:
            if _debug: decode_packet._debug("    - decoding error: %r", err)
            return xpdu

        # success
        return npdu
647887
def _vn_decode(self, msg):
        """"""
        elkm1_version = "{}.{}.{}".format(int(msg[4:6], 16), int(msg[6:8], 16),
                                          int(msg[8:10], 16))
        xep_version = "{}.{}.{}".format(int(msg[10:12], 16), int(msg[12:14], 16),
                                        int(msg[14:16], 16))
        return {'elkm1_version': elkm1_version, 'xep_version': xep_version}
390194
def _cr_decode(self, msg):
        """"""
        if int(msg[4:6]) > 0:
            index = int(msg[4:6])-1
            return {'values': [self._cr_one_custom_value_decode(index, msg[6:12])]}
        else:
            part = 6
            ret = []
            for i in range(Max.SETTINGS.value):
                ret.append(self._cr_one_custom_value_decode(i, msg[part:part+6]))
                part += 6
            return {'values': ret}
935699
private function decodeWIF($WIF_encoded_key)
    {
        /* Using the Base58 decoding function and remove the padding. */
        $decoded_key = $this->stripHexPrefix($this->decodeBase58(trim($WIF_encoded_key)));

        list($private_key, $checksum_provided) = array(
                                                       substr($decoded_key, 0, -8), 
                                                       substr($decoded_key, strlen($decoded_key) - 8)
                                                       );

        $private_key_type = substr($private_key, 0, 2);

        if ($private_key_type != '80' && $private_key_type != 'ef') {
            throw new \Exception('Invalid WIF encoded private key! Network type was not present in value provided. Checked ' . $private_key . ' and found ' . $private_key_type);
        }

        $private_key           = substr($private_key, 2);
        $compressed_public_key = (substr($private_key, strlen($private_key) - 2) == '01') ? '01' : '';
        $private_key           = ($compressed_public_key == '01') ? substr($private_key, 0, -2) : $private_key;

        /* Now let's check our private key against the checksum provided. */
        $new_checksum = substr(hash('sha256', hash('sha256', $this->binConv($private_key_type . $private_key . $compressed_public_key), true)), 0, 8);

        if ($new_checksum != $checksum_provided) {
            throw new \Exception('Invalid WIF encoded private key! Checksum is incorrect! Value encoded with key was: ' . $checksum_provided . ' but this does not match the recalculated value of: ' . $new_checksum . ' from the decoded provided value of: ' . $decoded_key);
        }

        return $private_key;
    }
16
def p44(msg):
    
    d = hex2bin(data(msg))

    if d[34] == '0':
        return None

    p = bin2int(d[35:46])    # hPa

    return p
738464
def decode_rfc2231(s):
    """"""
    parts = s.split(TICK, 2)
    if len(parts) <= 2:
        return None, None, s
    return parts
759248
function(bytes) {
  var result = "";
  var i = 0;
  var wc;
  var c;

  while (i < bytes.length) {
    /* parse as UTF-8 lead byte */
    wc = bytes[i++];
    if (wc < 0x80) {
      count = 0;
    } else if (wc < 0xC2 || wc >= 0xF8) {
      throw new Error("input is not a valid UTF-8 lead octet");
    } else if (wc < 0xE0) {
      count = 1;
      wc = (wc & 0x1F) << 6;
    } else if (wc < 0xF0) {
      count = 2;
      wc = (wc & 0x0F) << 12;
    } else /* wc < 0xF8 */ {
      count = 3;
      wc = (wc & 0x07) << 18;
    }

    /* parse trail bytes, if any */
    while (count) {
      if (!(i < bytes.length)) {
        throw new Error("short read");
      }
      if ((c = bytes[i++] ^ 0x80) > 0x3F) {
        throw new Error("input is not a valid UTF-8 trail octet");
      }
      wc |= c << (6 * --count);
      if (wc < (1 << (5 * count + 6))) {
        throw new Error("invalid non-minimal encoded input");
      }
    }

    /* handle conversion to UTF-16 if needed */
    if (wc > 0xFFFF) {
      wc -= 0x10000;
      result += String.fromCharCode(0xD800 + (wc >> 10));
      wc = 0xDC00 + (wc & 0x3FF);
    }
    result += String.fromCharCode(wc);
  }

  return result;
}
195479
def _pc_decode(self, msg):
        """"""
        housecode = msg[4:7]
        return {'housecode': housecode, 'index': housecode_to_index(housecode),
                'light_level': int(msg[7:9])}
540710
def get_decode_value(self):
        """"""
        if self._store_type == PUBLIC_KEY_STORE_TYPE_HEX:
            value = bytes.fromhex(self._value)
        elif self._store_type == PUBLIC_KEY_STORE_TYPE_BASE64:
            value = b64decode(self._value)
        elif self._store_type == PUBLIC_KEY_STORE_TYPE_BASE85:
            value = b85decode(self._value)
        elif self._store_type == PUBLIC_KEY_STORE_TYPE_JWK:
            # TODO: need to decide on which jwk library to import?
            raise NotImplementedError
        else:
            value = self._value
        return value
148873
def decode(self):
        """"""
        hi = self.enc_byte()
        flagbits = 0
        while self.encpos < len(self.encdata):
            if flagbits == 0:
                flags = self.enc_byte()
                flagbits = 8
            flagbits -= 2
            t = (flags >> flagbits) & 3
            if t == 0:
                self.put(self.enc_byte(), 0)
            elif t == 1:
                self.put(self.enc_byte(), hi)
            elif t == 2:
                self.put(self.enc_byte(), self.enc_byte())
            else:
                n = self.enc_byte()
                if n & 0x80:
                    c = self.enc_byte()
                    for _ in range((n & 0x7f) + 2):
                        lo = (self.std_byte() + c) & 0xFF
                        self.put(lo, hi)
                else:
                    for _ in range(n + 2):
                        self.put(self.std_byte(), 0)
        return self.buf.decode("utf-16le", "replace")
2181
def decode(self, packet):
        """"""

        ssu=packet.retrieve("Complete uuids")
        found=False
        for x in ssu:
            if EDDY_UUID in x:
                found=True
                break
        if not found:
            return None

        found=False
        adv=packet.retrieve("Advertised Data")
        for x in adv:
            luuid=x.retrieve("Service Data uuid")
            for uuid in luuid:
                if EDDY_UUID == uuid:
                    found=x
                    break
            if found:
                break


        if not found:
            return None

        try:
            top=found.retrieve("Adv Payload")[0]
        except:
            return None
        #Rebuild that part of the structure
        found.payload.remove(top)
        #Now decode
        result={}
        data=top.val
        etype = aios.EnumByte("type",self.type.val,{ESType.uid.value:"Eddystone-UID",
                                                ESType.url.value:"Eddystone-URL",
                                                ESType.tlm.value:"Eddystone-TLM",
                                                ESType.eid.value:"Eddystone-EID"})
        data=etype.decode(data)
        found.payload.append(etype)
        if etype.val== ESType.uid.value:
            power=aios.IntByte("tx_power")
            data=power.decode(data)
            found.payload.append(power)
            result["tx_power"]=power.val

            nspace=aios.Itself("namespace")
            xx=nspace.decode(data[:10])  #According to https://github.com/google/eddystone/tree/master/eddystone-uid
            data=data[10:]
            found.payload.append(nspace)
            result["name space"]=nspace.val

            nspace=aios.Itself("instance")
            xx=nspace.decode(data[:6])  #According to https://github.com/google/eddystone/tree/master/eddystone-uid
            data=data[6:]
            found.payload.append(nspace)
            result["instance"]=nspace.val

        elif etype.val== ESType.url.value:
            power=aios.IntByte("tx_power")
            data=power.decode(data)
            found.payload.append(power)
            result["tx_power"]=power.val

            url=aios.EnumByte("type",0,{0x00:"http://www.",0x01:"https://www.",0x02:"http://",0x03:"https://"})
            data=url.decode(data)
            result["url"]=url.strval
            for x in data:
                if bytes([x]) == b"\x00":
                    result["url"]+=".com/"
                elif bytes([x]) == b"\x01":
                    result["url"]+=".org/"
                elif bytes([x]) == b"\x02":
                    result["url"]+=".edu/"
                elif bytes([x]) == b"\x03":
                    result["url"]+=".net/"
                elif bytes([x]) == b"\x04":
                    result["url"]+=".info/"
                elif bytes([x]) == b"\x05":
                    result["url"]+=".biz/"
                elif bytes([x]) == b"\x06":
                    result["url"]+=".gov/"
                elif bytes([x]) == b"\x07":
                    result["url"]+=".com"
                elif bytes([x]) == b"\x08":
                    result["url"]+=".org"
                elif bytes([x]) == b"\x09":
                    result["url"]+=".edu"
                elif bytes([x]) == b"\x10":
                    result["url"]+=".net"
                elif bytes([x]) == b"\x11":
                    result["url"]+=".info"
                elif bytes([x]) == b"\x12":
                    result["url"]+=".biz"
                elif bytes([x]) == b"\x13":
                    result["url"]+=".gov"
                else:
                    result["url"]+=chr(x) #x.decode("ascii") #Yep ASCII only
                    url=aios.String("url")
            url.decode(result["url"])
            found.payload.append(url)
        elif etype.val== ESType.tlm.value:
            myinfo=aios.IntByte("version")
            data=myinfo.decode(data)
            found.payload.append(myinfo)
            myinfo=aios.ShortInt("battery")
            data=myinfo.decode(data)
            result["battery"]=myinfo.val
            found.payload.append(myinfo)
            myinfo=aios.Float88("temperature")
            data=myinfo.decode(data)
            found.payload.append(myinfo)
            result["temperature"]=myinfo.val
            myinfo=aios.LongInt("pdu count")
            data=myinfo.decode(data)
            found.payload.append(myinfo)
            result["pdu count"]=myinfo.val
            myinfo=aios.LongInt("uptime")
            data=myinfo.decode(data)
            found.payload.append(myinfo)
            result["uptime"]=myinfo.val*100 #in msecs
            return result
        #elif etype.val== ESType.tlm.eid:
        else:
            result["data"]=data
            xx=Itself("data")
            xx.decode(data)
            found.payload.append(xx)

        rssi=packet.retrieve("rssi")
        if rssi:
            result["rssi"]=rssi[-1].val
        mac=packet.retrieve("peer")
        if mac:
            result["mac address"]=mac[-1].val
        return result
520044
def _get_c_string(data, position):
    """"""
    end = data.index(b"\x00", position)
    return _utf_8_decode(data[position:end], None, True)[0], end + 1
979952
def decode(self, pdu):
        """"""
        if _debug: BVLCI._debug("decode %s", str(pdu))

        # copy the basics
        PCI.update(self, pdu)

        self.bvlciType = pdu.get()
        if self.bvlciType != 0x81:
            raise DecodingError("invalid BVLCI type")

        self.bvlciFunction = pdu.get()
        self.bvlciLength = pdu.get_short()

        if (self.bvlciLength != len(pdu.pduData) + 4):
            raise DecodingError("invalid BVLCI length")