Difference between revisions of "Piñata Vision barcode/Obfuscation set"
FeralKitty (talk  contribs) (Shuffle table for obfuscation sets) 
FeralKitty (talk  contribs) (Add transformation table, check digit to obfuscation set table. Update article to match decoder approach to deobfuscation.) 

Line 5:  Line 5:  
Obfuscation is the process of concealing the Piñata Vision card's data, making it difficult to interpret.  Obfuscation is the process of concealing the Piñata Vision card's data, making it difficult to interpret.  
−  Deobfuscating (or obfuscating) card data involves two steps. First the card data is converted from barcode representation to obfuscated binary data. Next the obfuscated bits are deobfuscated,  +  Deobfuscating (or obfuscating) card data involves two steps. First the card data is converted from barcode representation to obfuscated binary data. Next the obfuscated bits are deobfuscated by applying a logical transformation, negating various bits, then (re)shuffling them (back into their proper order). 
=== Logical transformations ===  === Logical transformations ===  
Line 19:  Line 19:  
* ''d'' = <sup>''d''</sup>(w x y z) = (!''bit w''  !''bit x'' & !''bit y'' ^ ''bit z'')  * ''d'' = <sup>''d''</sup>(w x y z) = (!''bit w''  !''bit x'' & !''bit y'' ^ ''bit z'')  
+  { class="collapsible collapsed"  
+  !abcd to wxyz transformation  
+    
+    
+  { border="1" class="pii_species_variants sortable"  
+  !abcd!!wxyz  
+    
+  00000111  
+    
+  00010110  
+    
+  00100101  
+    
+  00110100  
+    
+  01000011  
+    
+  01010010  
+    
+  01100001  
+    
+  01110000  
+    
+  10001110  
+    
+  10011111  
+    
+  10101010  
+    
+  10111011  
+    
+  11001100  
+    
+  11011101  
+    
+  11101001  
+    
+  11111000  
+  }  
+  }  
+  
+  Since the result for a particular translation is known (based on each possible input), we can replace the actual logical operations with a direct substitution of each translated value back to its original input value. I.e., tr 76543210EFABCD98 09AF.  
+  
=== Bit shuffling ===  === Bit shuffling ===  
Bit shuffling makes it harder to spot sequences of bits, by rearranging the order of the bits. Given a sequence of bits ''wxyzwxyzwxyz...'', the obfuscation could shuffle them in a variety of ways, such as ''wwwxxxyyyzzz...''  Bit shuffling makes it harder to spot sequences of bits, by rearranging the order of the bits. Given a sequence of bits ''wxyzwxyzwxyz...'', the obfuscation could shuffle them in a variety of ways, such as ''wwwxxxyyyzzz...''  
−  
−  
−  
−  
== Obfuscation sets ==  == Obfuscation sets ==  
−  Using those variety of techniques, and by  +  Using those variety of techniques, and by varying how bits are shuffled and negated for each obfuscation, the game can produce 16 different variations of obfuscated data. Each particular variation is called an obfuscation set (since all data in that set is obfuscated using the same variation). Having examined all 16 obfuscation sets for ID bits, each set sharing a common last byte uses the same columns for its obfuscated ID bits. (See the [[Piñata Vision barcode/Choclodocus egg cardChoclodocus egg card]] article for an example of an obfuscation set's ID bit locations.) 
−  Each obfuscation set is given a 4bit value that identifies the specific obfuscation used to produce that obfuscated data. The game recognizes which particular obfuscation was used by examining the last byte of a barcode's row.  +  Each obfuscation set is given a 4bit value (related to a check digit) that identifies the specific obfuscation used to produce that obfuscated data. The game recognizes which particular obfuscation was used by examining the last byte of a barcode's row. 
=== Multirow cards ===  === Multirow cards ===  
Line 39:  Line 78:  
To deobfuscate this card, we'd have to deobfuscate row 1 by reversing the set 2 obfuscation method, deobfuscate obfuscation set 3 in row 2, and finally deobfuscate set 9 in the last row, before joining all the deobfuscated rows together to reveal the encoded data.  To deobfuscate this card, we'd have to deobfuscate row 1 by reversing the set 2 obfuscation method, deobfuscate obfuscation set 3 in row 2, and finally deobfuscate set 9 in the last row, before joining all the deobfuscated rows together to reveal the encoded data.  
−  This seems like a complicated process, but it can be optimized by normalizing the obfuscations (i.e., shuffling  +  This seems like a complicated process, but it can be optimized by normalizing the obfuscations (i.e., shuffling and negating bits so that the obfuscated bits are once again returned to their original order and values, then transforming groups of bits back to the original encoded data. 
== Obfuscation set selection ==  == Obfuscation set selection ==  
Line 46:  Line 85:  
This 4bit check digit maps to one of the 16 possible obfuscation sets.  This 4bit check digit maps to one of the 16 possible obfuscation sets.  
+  { class="collapsible collapsed"  
+  !Check digit to obfuscation set  
+    
+    
+  { border="1" class="pii_species_variants"  
+    
+  !Check digit!!Obfuscation set  
+    
+  00  
+    
+  11  
+    
+  22  
+    
+  33  
+    
+  44  
+    
+  55  
+    
+  66  
+    
+  77  
+    
+  88  
+    
+  99  
+    
+  10D  
+    
+  11C  
+    
+  12B  
+    
+  13A  
+    
+  14F  
+    
+  15E  
+    
+  }  
+  }  
=== Example calculation ===  === Example calculation === 
Latest revision as of 13:32, 26 February 2013
The Piñata Vision barcode article discusses obfuscation (of the barcode) in general.
Pinata Vision obfuscation
Obfuscation is the process of concealing the Piñata Vision card's data, making it difficult to interpret.
Deobfuscating (or obfuscating) card data involves two steps. First the card data is converted from barcode representation to obfuscated binary data. Next the obfuscated bits are deobfuscated by applying a logical transformation, negating various bits, then (re)shuffling them (back into their proper order).
Logical transformations
Using functions involving AND, OR, XOR (exclusive OR), and NOT, obfuscated bits can be transformed into more readable values.
In these examples, we'll represent obfuscated bits by w, x, y, and z, and the corresponding deobfuscated values by a, b, c, and d.
Given 4 bits of obfuscated data, and four functions to reverse the obfuscation, we see that:
 a = ^{a}(x) = (bit x)
 b = ^{b}(x y z) = (!bit x & !bit y  bit z ^ (bit x  bit y & bit z))
 c = ^{c}(x y z) = (!bit x  bit y  !bit z ^ (bit x & bit y  bit z))
 d = ^{d}(w x y z) = (!bit w  !bit x & !bit y ^ bit z)
abcd to wxyz transformation  


Since the result for a particular translation is known (based on each possible input), we can replace the actual logical operations with a direct substitution of each translated value back to its original input value. I.e., tr 76543210EFABCD98 09AF.
Bit shuffling
Bit shuffling makes it harder to spot sequences of bits, by rearranging the order of the bits. Given a sequence of bits wxyzwxyzwxyz..., the obfuscation could shuffle them in a variety of ways, such as wwwxxxyyyzzz...
Obfuscation sets
Using those variety of techniques, and by varying how bits are shuffled and negated for each obfuscation, the game can produce 16 different variations of obfuscated data. Each particular variation is called an obfuscation set (since all data in that set is obfuscated using the same variation). Having examined all 16 obfuscation sets for ID bits, each set sharing a common last byte uses the same columns for its obfuscated ID bits. (See the Choclodocus egg card article for an example of an obfuscation set's ID bit locations.)
Each obfuscation set is given a 4bit value (related to a check digit) that identifies the specific obfuscation used to produce that obfuscated data. The game recognizes which particular obfuscation was used by examining the last byte of a barcode's row.
Multirow cards
Based on the name example, each barcode row has its own trailing obfuscation set byte, and is obfuscated independently of other rows. For example, this accessorized Galagoogoo green variant has a 3row barcode on its card. Its barcode is represented in hexadecimal as A2141426B00E1A42 B11F620521256E13 E02E7793D1F0E869. Notice that the last byte of each row happens to indicate a different obfuscation set, meaning that each row is obfuscated using a different technique from the other rows.
To deobfuscate this card, we'd have to deobfuscate row 1 by reversing the set 2 obfuscation method, deobfuscate obfuscation set 3 in row 2, and finally deobfuscate set 9 in the last row, before joining all the deobfuscated rows together to reveal the encoded data.
This seems like a complicated process, but it can be optimized by normalizing the obfuscations (i.e., shuffling and negating bits so that the obfuscated bits are once again returned to their original order and values, then transforming groups of bits back to the original encoded data.
Obfuscation set selection
The method of selecting an obfuscation for a row of encoded data involves computing a weighted checksum digit, similar to the EAN check digit. Alternating weights of 3 and 1 are used, with the 15th digit having a weight of 3. The weighted values are summed. The check digit is the value which when added to the sum yields a number evenly divisible by 16. (I.e., modulo 16 of the sum plus the check digit will equal 0.)
This 4bit check digit maps to one of the 16 possible obfuscation sets.
Check digit to obfuscation set  


Example calculation
Using the encoded (unobfuscated) data for a free Macaracoon life sweet as an example, compute a weighted value for each 4bit digit by multiplying the (decimal) value of the hex digit by the weight.
Encoded data  0  0  8  5  B  0  2  C  0  0  0  6  B  2  3 
Weight  3  1  3  1  3  1  3  1  3  1  3  1  3  1  3 
Weighted value  0  0  24  5  33  0  6  12  0  0  0  6  33  2  9 
The sum of the weighted values is 130. 14 would have to be added to the sum to make it evenly divisible by 16. I.e., (130 + 14) % 16 = 0, so the check digit is 14.
Sample illustrating that similarlyobfuscated cards share the same check digit 

% egrep 'Generated_PlaceTag_Sweet_[prst]' barcodes.txt  ./barcodetxt2bitdiff.pl short  ./checksum3.pl  sort key=3.17 Sweet_pony 1725 A5F8F4664D0A5792 sum = 174 check = 2 Sweet_rabbit 1727 A568F4664D0A57C2 sum = 222 check = 2 Sweet_spider 1733 CBFFD156B86FC2E4 sum = 156 check = 4 Sweet_pig 1721 DBF6D516F87BD0F4 sum = 172 check = 4 Sweet_snail 1750 DB6FF154B97FC2E4 sum = 188 check = 4 Sweet_swan 1735 CB6FD154B86FC2E4 sum = 204 check = 4 Sweet_poisonfrog 1723 DB66D514F87BD0F4 sum = 220 check = 4 Sweet_redbutterfly 1729 96FEDBAEAB02C656 sum = 154 check = 6 Sweet_sheep 1731 96EADBAEAB02C656 sum = 202 check = 6 Sweet_sparrow 1732 D76190A0ADE39B2B sum = 132 check = 12 Sweet_parrot 1720 D76190A0AD58492B sum = 148 check = 12 Sweet_squirrel 1734 D76190A0ADE3CB6B sum = 180 check = 12 Sweet_pigeon 1722 D76190A0AD58696B sum = 196 check = 12 Sweet_pinkbutterfly 1724 B57070E0C9170B3D sum = 150 check = 10 Sweet_purplebutterfl 1726 BA7070E039170B3D sum = 198 check = 10 Sweet_raccoon 1728 F170696DC403538F sum = 130 check = 14 
It doesn't matter if the row being obfuscated is row 1 or a different row. The game simply computes the check digit for the row of data to be obfuscated, regardless of what data is within that row. So, the game might be obfuscating accessory details or a pinata name, but that's all transparent to the obfuscation that's taking place.
Obfuscation set progression
IDs  Obfuscation set progression 

0 to 15  0 8 0 8 F 6 F 6 0 8 0 8 F 6 F 6 
16 to 31  8 0 8 0 6 F 6 F 8 0 8 0 6 F 6 F 
32 to 47  0 8 0 8 F 6 F 6 0 8 0 8 F 6 F 6 
48 to 63  8 0 8 0 6 F 6 F 8 0 8 0 6 F 6 F 
As shown in the ID table, obfuscation sets alternate in two groups of four, and repeat a predictable sequence every 64 IDs. The following can be noted about the table:
 Each group of four cards uses 2 different obfuscations. The even/odd IDs of the group only differ by a single unobfuscated bit (i.e., ID bit 1).
 Every 16 IDs, the order within the group of four will alternate. E.g., the first group may start as A, B, A, B, but 16 cards later, their order will have changed to B, A, B, A.
 Similarly obfuscated cards can always be located 2, 8, or 32 IDs away. (They can also be located 512, 1024, and 2048 IDs away, as the progression cycles through the different sets and restarts itself.) This is a key detail in finding similarly obfuscated (PlaceTag) cards that only differ by a single ID bit.
Interpolation of obfuscation set data
Due to the repeating pattern of similarly obfuscated cards appearing 2 cards apart, and possibly 8 (or 9) cards apart, if the obfuscation set appears in the next progression, it's possible to interpolate data for missing cards, based on the pattern of differing obfuscated bits seen 2 (or 8) cards apart.
This can be done by comparing a pair of cards (from the same obfuscation set) to see which obfuscated bits differ. For example, (PlaceTag) cards for IDs 309 and 311 from obfuscation set 96 6 show the following minor difference (as the card's unobfuscated data changes ID bit 1 from 0 to 1, the barcode's obfuscated data changes bits 52 and 50 from 01 to 10):
egrep "(03090311)" 96_no_banjostatue.txt  ./bit_diff.pl 55 Description VPID Barcode 20  Egg_walrus 0309 926EDF96E548F4A6 01 0x0135 0b0000000100110101 Egg_whitebutterfly 0311 927ADF96E548F4A6 10 0x0137 0b0000000100110111 ID bit 1 to match 01 Exact match(es): 52, !50
Once a specific pattern is recognized, it can be used to fill in a missing card's barcode, based on the barcode from a similarly obfuscated card located 2 cards away. This comparison method can also be applied to cards located further (e.g., 8 or 32 cards) away, as long as they're from the same obfuscation set.
This process could even be automated by a script that scans the ID table, makes comparisons between alternating cards to recognize a particular obfuscation set's specific patterns, then applies that pattern to fill in missing ID table card barcodes.
Decoding
Decoded obfuscation sets
 Obfuscation set 0
 Obfuscation set 1
 Obfuscation set 2
 Obfuscation set 3
 Obfuscation set 4
 Obfuscation set 5
 Obfuscation set 6
 Obfuscation set 7
 Obfuscation set 8
 Obfuscation set 9
 Obfuscation set A
 Obfuscation set B
 Obfuscation set C
 Obfuscation set D
 Obfuscation set E
 Obfuscation set F
Decoded columns for obfuscation sets
The different sets share a common manner of obfuscation, although each set's bits are shuffled and negated differently to give the appearance of significantly different obfuscations.
Bit  Offset  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F 

63  0  63   63   63   63   63   63   63   63   63   63   63   63   63   63   63   63  
62  1  62  33   43  51  54  56  57  58  59  59  61   60   60  60   61  61 
61  2  61  62  23  39   45  49  51   53   55   55  59  57  57   57   59  59 
60  3  60  32   62  27   36  42   45  48  51  51   57  55  54  54  57   57  
59  4  59  61  42  15  27   35  39   43  47   48  55   53  51   51  55   55 
58  5  58   31  22   62  19   28   33  38  43  45  53  51  48   48   53  53 
57  6  57   60   61   50   11  21   28  33   39   42  51   49   45  45  51   51 
56  7  56   30   41   38  62   15  23  28   35  39   49   47   43   42   49   49  
55  8  55   59  21  26  53   09  18  23  31   36  47  45  41   39  47  47  
54  9  54  29  60  14   44   62   13  19  27   33  45  43  39  36  45  45 
53  10  53  58   40   61   35  55  08   15  24   30  43  41   37   33   43   43  
52  11  52  28   20   49   26   48   62   11   21  27   41   39   35  30   41   41  
51  12  51   57   59  37   18  41   56   07  18  24  39   37   33  27   39  39 
50  13  50   27   39   25   10  34  50   62   15  21  37  35   31   24   37  37  
49  14  49   56  19   13   61  27   44   57  12  18  35   33   29   21   35   35  
48  15  48   26  58   60   52  20  38   52   09  15   33  31  27   19   33  33  
47  16  47  55  38   48  43   14   32   47   06   12  31  29  25  17   31  31 
46  17  46  25  18  36  34  08   27   42   62   09  29   27   23  15  29   29 
45  18  45  54  57  24   25  61  22  37   58  06  27   25   21   13  27   27  
44  19  44  24   37  12  17   54  17   32   54  62   25   23  19  11   25  25 
43  20  43   53  17  59  09  47   12  27   50   58  23  21  17   09  23  23 
42  21  42  23  56   47   60  40  07  22  46  54  21  19  15   07   21   21  
41  22  41   52  36  35   51   33   61   18  42   50   19   17  13  05   20   19 
40  23  40   22   16   23  42  26   55   14   38  47  17  15  11  62   19   17 
39  24  39  51  55   11   33  19  49  10   34   44   15   13   09  59  18  16 
38  25  38   21   35   58   24  13  43  06   30  41   13   11   07   56  17  15 
37  26  37  50   15   46   16  07   37  61   26   38   11  09  05   53   16  14  
36  27  36  20  54  34   08   60   31   56  23  35  09  07  62   50   15   13  
35  28  35   49   34   22   59  53   26   51  20  32   07  05   59  47   14   12  
34  29  34  19  14   10   50   46   21  46   17   29   05   62  56   44   13   11  
33  30  33  48   53  57  41   39  16   41   14   26   04   59  53   41   12   10  
32  31  32   18  33  45  32   32   11  36  11   23  62  56  50   38  11  09 
31  32  31  47   13   33   23  25  06  31   08   20   60  54  47  35  10  08 
30  33  30   17  52   21  15   18  60  26   05   17   58   52   44   32   09  07  
29  34  29   46   32   09  07   12   54  21  61   14   56   50   42  29  08  06  
28  35  28  16  12  56  58  06   48  17   57  11  54  48  40  26   07   05  
27  36  27   45  51   44  49  59  42  13  53   08   52   46   38   23  06  04  
26  37  26  15  31  32   40  52  36  09  49  05   50   44  36  20  05   62 
25  38  25  44  11  20  31   45  30  05   45  61   48  42   34  18  04   60  
24  39  24  14   50   08  22  38  25   60   41   57  46  40   32   16  62  58  
23  40  23  43   30  55  14   31   20   55  37  53   44  38  30   14   60  56 
22  41  22   13   10  43  06  24   15   50   33   49  42  36  28   12   58   54 
21  42  21   42   49   31  57   17   10  45  29  46   40   34   26   10  56   52 
20  43  20   12   29   19  48   11   05   40  25   43  38   32   24  08   54  50  
19  44  19   41   09  07  39  05   59  35  22  40  36  30  22  06   52  48  
18  45  18  11   48  54  30   58  53   30  19   37   34   28   20   04   50   46  
17  46  17  40   28  42   21   51  47  25   16   34   32   26  18  61  48   44 
16  47  16  10   08  30  13  44   41   20  13  31   30  24   16  58  46  42  
15  48  15   39  47  18  05   37   35  16   10  28   28  22   14   55   44  40  
14  49  14   09  27   06   56   30   29   12  07  25   26  20  12   52  42  38 
13  50  13   38  07  53  47  23  24  08   04   22  24  18  10   49  40   36 
12  51  12   08  46  41   38   16  19   04   60   19  22   16   08   46  38   34 
11  52  11  37   26  29  29   10   14   59  56  16   20   14   06  43   36  32  
10  53  10  07   06  17  20   04   09  54  52   13  18  12  04   40  34  30  
9  54  09  36  45  05   12   57   04   49  48  10   16   10   61  37  32   28  
8  55  08  06   25   52   04   50   58  44   44   07  14   08  58  34  30   26 
7  56  07   35   05   40   55   43   52   39   40  04   12  06   55  31   28  24  
6  57  06  05   44  28   46  36  46  34   36  60  10  04   52  28  26  22  
5  58  05   34  24  16   37  29  40  29  32   56   08  61   49  25  24  20 
4  59  04   04   04   04   28  22  34   24   28  52   06  58   46   22  22   18 
3  60  03  03  03  03  03  03  03  03  03  03  03  03  03  03  03  03 
2  61  02  02  02  02  02  02  02  02  02  02  02  02  02  02  02  02 
1  62  01  01  01  01  01  01  01  01  01  01  01  01  01  01  01  01 
0  63  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 