The musings, struggles and observations of an Englishman learning Welsh.
return ((in & 0x0000007F) |bit mask %00000000 00000000 00000000 01111111
((in & 0x00003F80) << 1) |bit mask %00000000 00000000 00111111 10000000
((in & 0x001FC000) << 2) |bit mask %00000000 00011111 11000000 00000000
((in & 0x0FE00000) << 3));bit mask %00001111 11100000 00000000 00000000
g a sync-safe integer from a regular integer.
The decoding sequence is just the reverse:
return ((in & 0x0000007F) | // bit mask %00000000 00000000 00000000 01111111
((in & 0x00007F00) >> 1) |bit mask %00000000 00000000 01111111 00000000
((in & 0x007F0000) >> 2) |bit mask %00000000 01111111 00000000 00000000
((in & 0x7F000000) >> 3)); // bit mask %01111111 00000000 00000000 00000000
In both cases, the ORed instructions are independent of each other in the sense that each has its bitmask applied and is shifted BEFORE all four results are ORed together.
And using this approach I was able to now correctly identify the length of the ID3 tags. Note, this value includes any padding at the end of the tags and before the audio data.
So that's sync safe integers - something you'll never encounter outside the realms of writing a decoder for ID3 tags.{ "targetOrigins": &["http://localhost"&] }{ "fields\": {"paymentInformation": {"card": {"number": { },"securityCode": {"required": false}}}},"targetOrigins": &["https://localhost"&]}<?php$url = 'https://apitest.cybersource.com/microform/v2/sessions';$merchantId = 'testres';$keyId = '08c94330-f618-42a3-b09d-e1e43be5efda';$sharedKey = 'yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE=';$host = 'apitest.cybersource.com';$data = "{\"fields\": {\"paymentInformation\": {\"card\": {\"number\": { },\"securityCode\": {\"required\": false}}}},\"targetOrigins\": &[\"https://localhost\"&]}";$hash = hash("sha256", $data, true);$digest = base64_encode($hash);$date = date("D, d M Y G:i:s")." GMT";$sigstring = "host: apitest.cybersource.com\ndate: $date\n(request-target): post /microform/v2/sessions\ndigest: SHA-256=$digest\nv-c-merchant-id: $merchantId";$sigstringbytes = utf8_encode($sigstring);echo "$sigstring\n";$rawkey = base64_decode($sharedKey);$hashval = hash_hmac("sha256", $sigstringbytes, $rawkey, true);$sighash = base64_encode($hashval);
$headers = array(
"Accept-Language: en-GB,en;q=0.5",
"Accept-Encoding: gzip, deflate, br",
"digest: SHA-256=".$digest,
"v-c-merchant-id: ".$merchantId,
"v-c-date: ".$date,
"date: ".$date,
"signature: keyid=\"".$keyId."\", algorithm=\"HmacSHA256\", headers=\"host date (request-target) digest v-c-merchant-id\", signature=\"".$sighash."\"",
"host: apitest.cybersource.com",
"Content-Type: application/json"
);
$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_POST, true);curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);curl_setopt($curl, CURLOPT_POSTFIELDS, $data);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//curl_setopt($curl, CURLOPT_PROXY, "127.0.0.1:8888"); // Uncomment to see traffic in a traffic analyser like Fiddlercurl_setopt($curl, CURLOPT_RETURNTRANSFER, true);$resp = curl_exec($curl);curl_close($curl);echo $resp."\n";?>