Piñata Vision barcode/Obfuscation set

From PinataIsland.info, the Viva Piñata wiki
Revision as of 12:50, 15 March 2011 by FeralKitty (talk | contribs) (Possible set selection bit values for remaining 8 sets)
Jump to: navigation, search

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, using a combination of techniques.

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)

Bit shuffling

Bit shuffling makes it harder to spot sequences of bits, by rearranging the order of the bits. Given a sequence of bits wxyzwzyzwxyz..., the obfuscation could shuffle them in a variety of ways, such as wwwxxxyyyzzz...

Bit rotation

Bit rotation shifts bits left or right in a circular manner, preserving all existing bits. Given a sequence of bits wxyz..., shifting right 4 bits would produce ....wxyz.

Obfuscation sets

Using those variety of techniques, and by shuffling and/or rotating bits a differing amount 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 4-bit 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.

Multi-row 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 3-row 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 or rotating particular bits so that the obfuscated bits are once again returned to their original order, then simply deobfuscating all rows using the common functions to return the deobfuscated bit values.

Obfuscation set selection

The method of selecting an obfuscation for the card's data involves specific bits following the card type field. Since the most common type of cards are ID-based, the obfuscation often happens to use those ID bits to determine what obfuscation to use. See the ID table for a pattern/grouping of obfuscated cards. Again, not every type of card has an ID field, and the obfuscation is selected based on bit values that follow the card type field, whether or not those bits happen to be ID bits or not.

It also doesn't matter if the row being obfuscated is row 1 or a different row. The game simply examines the same specific bits within that chunk of data to be obfuscated, regardless of what data is within that chunk. So, the game might be obfuscating accessory details or a pinata name, but that's all transparent to the obfuscation that's taking place.

Based on (PlaceTag card type) ID table cards (which have no use cost), only 8 of the 16 obfuscation sets are used in selection of an obfuscation set for a particular card. To determine the correct obfuscation (set) for a card's data, the following bits are used from the ID field:

Bits Set Bit 3 Bit 2 Bit 1 Bit 0
0001 6 ID bit 8 ^ ID bit 4 ^ ! ID bit 0 == 0 !ID7 ^ !ID6 & ID2 !ID6 ^ ID2 ?
0011 4 ID bit 8 ^ ID bit 4 ^ ID bit 2 ^ ID bit 0 == 0 ?
0101 D ID bit 8 ^ ID bit 4 ^ ID bit 2 ^ ID bit 0 == 0 ?
0111 0 ID bit 8 ^ ID bit 4 ^ ID bit 2 ^ ID bit 0 == 0 ?
1001 F ID bit 8 ^ ID bit 4 ^ ! ID bit 0 == 1 ?
1011 B ID bit 8 ^ ID bit 4 ^ ID bit 2 ^ ID bit 0 == 1 ?
1101 2 ID bit 8 ^ ID bit 4 ^ ID bit 2 ^ ID bit 0 == 1 ?
1111 8 ID bit 8 ^ ID bit 4 ^ ID bit 2 ^ ID bit 0 == 1 ?
0000 7? ? ? ? ?
0010 5? ? ? ? ?
0100 C? ? ? ? ?
0110 1? ? ? ? ?
1000 9? ? ? ? ?
1010 A? ? ? ? ?
1100 3? ? ? ? ?
1110 E? ? ? ? ?

Obfuscation set progression

Obfuscation set used for IDs 0 to 63
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:

  1. 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).
  2. 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.
  3. 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 "(0309|0311)" 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.

List of obfuscation sets

The set count is based on unique barcodes (no duplicates).

The TroubleInParadise cards are wiki cards, and are not broken down by card type. The Other cards are wiki cards that don't match up with the image-naming convention.

Totaling the number of member cards may not match the count for various reasons:

  • Duplicate cards (e.g., card known by two names, such as Vision_Single_Placetag_Egg_dog and Barkbark-TroubleInParadise-Egg)
  • Omitted member cards (i.e., 010A22F91408B400D112.jpg from VivaPinata.com)

There appear to be 16 obfuscation sets.

Set Count Members
0 223 Appear_Cutscene (7) Blackariants (6) GoodVariants (6) Learn_Primary_Trick (6) Learn_Secondary_Trick (6) Mate_Cutscene (4) Other (23) Perform_Primary_Trick (5) Perform_Secondary_Trick (6) PlaceTag (69) RomanceMusic (1) TroubleInParadise (164) UnlockArt (7) ViewTagInJournal (11)
1 165 Appear_Cutscene (5) Blackariants (6) GoodVariants (7) House_Interior (1) Learn_Primary_Trick (4) Learn_Secondary_Trick (6) Mate_Cutscene (5) Other (29) Perform_Primary_Trick (7) Perform_Secondary_Trick (6) TroubleInParadise (139) UnlockArt (13) UnlockTag (3) ViewTagInJournal (6)
2 206 Appear_Cutscene (7) Blackariants (3) GoodVariants (5) Learn_Primary_Trick (7) Learn_Secondary_Trick (7) Mate_Cutscene (7) Other (15) Perform_Primary_Trick (6) Perform_Secondary_Trick (6) PlaceTag (67) RomanceMusic (1) TroubleInParadise (154) UnlockArt (5) ViewTagInJournal (6) Weather (1)
3 151 Appear_Cutscene (6) Blackariants (5) GoodVariants (11) House_Interior (1) Learn_Primary_Trick (6) Learn_Secondary_Trick (6) Mate_Cutscene (6) Other (19) Perform_Primary_Trick (6) Perform_Secondary_Trick (7) TimeWarp (1) TroubleInParadise (129) UnlockArt (7) ViewTagInJournal (5) Weather (1)
4 209 Appear_Cutscene (13) Blackariants (2) GoodVariants (9) Learn_Primary_Trick (7) Learn_Secondary_Trick (6) Mate_Cutscene (6) Other (18) Perform_Primary_Trick (6) Perform_Secondary_Trick (6) PlaceTag (62) TroubleInParadise (160) UnlockArt (7) ViewTagInJournal (9) Weather (2)
5 146 Appear_Cutscene (3) Blackariants (8) GoodVariants (4) Learn_Primary_Trick (4) Learn_Secondary_Trick (6) Mate_Cutscene (6) Other (25) Perform_Primary_Trick (7) Perform_Secondary_Trick (4) RomanceMusic (1) TroubleInParadise (122) UnlockArt (9) ViewTagInJournal (9)
6 205 Appear_Cutscene (6) Blackariants (5) GoodVariants (4) Learn_Primary_Trick (8) Learn_Secondary_Trick (7) Mate_Cutscene (7) Other (20) Perform_Primary_Trick (6) Perform_Secondary_Trick (8) PlaceTag (65) RomanceMusic (1) TimeWarp (1) TroubleInParadise (144) UnlockArt (7) ViewTagInJournal (5) Weather (4)
7 161 Appear_Cutscene (5) Blackariants (11) GoodVariants (4) Learn_Primary_Trick (4) Learn_Secondary_Trick (6) Mate_Cutscene (5) Other (24) Perform_Primary_Trick (4) Perform_Secondary_Trick (6) RomanceMusic (1) TroubleInParadise (136) UnlockArt (7) UnlockTag (3) ViewTagInJournal (8) Weather (1)
8 222 Appear_Cutscene (9) Blackariants (4) GoodVariants (7) Learn_Primary_Trick (5) Learn_Secondary_Trick (4) Mate_Cutscene (10) Other (24) Perform_Primary_Trick (7) Perform_Secondary_Trick (7) PlaceTag (65) RomanceMusic (1) TimeWarp (1) TroubleInParadise (160) UnlockArt (11) ViewTagInJournal (6)
9 159 Appear_Cutscene (7) Blackariants (10) GoodVariants (11) Learn_Primary_Trick (6) Learn_Secondary_Trick (7) Mate_Cutscene (5) Other (18) Perform_Primary_Trick (5) Perform_Secondary_Trick (4) RomanceMusic (3) TroubleInParadise (137) UnlockArt (7) UnlockTag (4) ViewTagInJournal (10)
A 123 Appear_Cutscene (9) Blackariants (5) GoodVariants (4) Learn_Primary_Trick (6) Learn_Secondary_Trick (8) Mate_Cutscene (7) Other (17) Perform_Primary_Trick (4) Perform_Secondary_Trick (6) RomanceMusic (1) TroubleInParadise (107) UnlockArt (7) ViewTagInJournal (2)
B 216 Appear_Cutscene (6) Blackariants (11) GoodVariants (5) Learn_Primary_Trick (6) Learn_Secondary_Trick (4) Mate_Cutscene (7) Other (25) Perform_Primary_Trick (8) Perform_Secondary_Trick (5) PlaceTag (68) TroubleInParadise (156) UnlockArt (10) ViewTagInJournal (9) Weather (1)
C 147 Appear_Cutscene (9) Blackariants (7) GoodVariants (7) Learn_Primary_Trick (7) Learn_Secondary_Trick (7) Mate_Cutscene (6) Other (19) Perform_Primary_Trick (4) Perform_Secondary_Trick (4) TroubleInParadise (128) UnlockArt (8) ViewTagInJournal (6) Weather (3)
D 241 Appear_Cutscene (7) Blackariants (5) GoodVariants (10) Learn_Primary_Trick (6) Learn_Secondary_Trick (6) Mate_Cutscene (7) Other (27) Perform_Primary_Trick (7) Perform_Secondary_Trick (8) PlaceTag (67) RomanceMusic (1) TroubleInParadise (174) UnlockArt (11) ViewTagInJournal (10) Weather (1)
E 151 Appear_Cutscene (9) Blackariants (10) GoodVariants (7) Learn_Primary_Trick (7) Learn_Secondary_Trick (5) Mate_Cutscene (10) Other (18) Perform_Primary_Trick (6) Perform_Secondary_Trick (7) TroubleInParadise (131) UnlockArt (11) UnlockTag (2) ViewTagInJournal (6) Weather (3)
F 204 Appear_Cutscene (9) Blackariants (4) GoodVariants (14) Learn_Primary_Trick (6) Learn_Secondary_Trick (4) Mate_Cutscene (6) Other (15) Perform_Primary_Trick (5) Perform_Secondary_Trick (5) PlaceTag (65) RomanceMusic (1) TimeWarp (1) TroubleInParadise (155) UnlockArt (7) ViewTagInJournal (9) Weather (1)

Decoding

Decoded obfuscation sets

Obfuscation method

Each obfuscation set stores their ID bits in the same columns. (See the Choclodocus egg card article for an example of ID bit diff results.) It's likely that all types of cards share the same obfuscation, although only the ID bit columns have been identified so far across all the obfuscation sets.

The different sets share a common manner of obfuscation, although each set is shuffled and/or rotated differently to give the appearance of significantly different obfuscations.

Decoded columns for ID bits

a(x) = (bit x)
b(x y z) = (!bit x & !bit y | bit z ^ (bit x | bit y & bit z))
c(x y z) = (!bit x | bit y | !bit z ^ (bit x & bit y | bit z))
d(w x y z) = (!bit w | !bit x & !bit y ^ bit z)

Set ID bit 11 ID bit 10 ID bit 9 ID bit 8 ID bit 7 ID bit 6 ID bit 5 ID bit 4 ID bit 3 ID bit 2 ID bit 1 ID bit 0
0 !(51 50 49)c !(51 50 49 48)d (47)a (47 46 45)b (47 46 45)c (47 46 45 44)d !(43)a (43 42 41)b !(43 42 41)c !(43 42 41 40)d (39)a !(39 38 37)b
1 (59 58 57 56)d (27 26 25)b (55)a (27 26 25)c (55 54 53)b !(27 26 25 24)d (55 54 53)c (23)a (55 54 53 52)d !(23 22 21)b (51)a !(23 22 21)c
2 !(19)a !(59 58 57)b !(39 38 37)b (19 18 17)b (59 58 57)c (39 38 37)c (19 18 17)c !(59 58 57 56)d (39 38 37 36)d !(19 18 17 16)d !(55)a !(35)a
3 !(15 14 13)c !(63 62 61 60)d (51 50 49 48)d (39 38 37 36)d !(27 26 25 24)d (15 14 13 12)d (59)a !(47)a !(35)a (23)a (11)a !(59 58 57)b
4 (63 62 61)c (55 54 53 52)d !(43)a (35 34 33)b (27 26 25)c !(19 18 17)c (11 10 9)c (63 62 61 60)d !(51)a (43 42 41)b (35 34 33)c (27 26 25 24)d
5 !(27)a (23 22 21 20)d !(15 14 13)b !(11 10 9 8)d (63 62 61)c (55 54 53)b !(47)a (43 42 41 40)d !(35 34 33)c !(27 26 25)b (19)a (15 14 13)c
6 !(47 46 45 44)d !(39 38 37)b !(35 34 33 32)d !(27)a (23 22 21)b !(19 18 17)c (15 14 13 12)d (7)a !(63 62 61)c !(55)a (51 50 49)c (43)a
7 (59 58 57)c !(55 54 53 52)d !(47)a !(43 42 41)b !(39 38 37)c !(35 34 33 32)d !(27)a (23 22 21)b (19 18 17)b !(15 14 13)b !(11 10 9)b !(7 6 5)b
8 (15 14 13 12)d (11 10 9)c !(7 6 5)b !(63 62 61)b (59 58 57)b (55 54 53)b !(51 50 49)b (47 46 45)b !(43 42 41)b (39 38 37)b !(35 34 33)b (31 30 29)b
9 (19 18 17)b !(15)a (15 14 13 12)d (11 10 9)c (7 6 5)b !(63 62 61)b (59 58 57)b (55 54 53)b !(51 50 49)b (47)a !(47 46 45 44)d !(43 42 41)c
A !(35)a (35 34 33)c (31)a !(31 30 29)c !(27)a !(27 26 25)c (23)a (23 22 21)c !(19)a (19 18 17)c !(15)a !(15 14 13)c
B !(35 34 33)c (31)a (31 30 29)c !(27)a !(27 26 25)c (23)a (23 22 21)c (19)a (19 18 17)c (15)a !(15 14 13)c !(11)a
C !(31 30 29)c (27)a (27 26 25)c (23)a (23 22 21)c (19)a !(19 18 17)c !(15)a (15 14 13)c (11)a (11 10 9)c !(7)a
D !(23 22 21)c !(19)a !(19 18 17)c (15)a (15 14 13)c !(11)a (11 10 9)c !(7)a !(7 6 5)c !(63 62 61)b (59)a (59 58 57 56)d
E !(35)a (35 34 33)c (31)a !(31 30 29)c !(27)a (27 26 25)c (23)a !(23 22 21)c !(23 22 21 20)d !(19)a (19 18 17)b (19 18 17)c
F !(35)a !(35 34 33)c (31)a (31 30 29)c !(27)a (27 26 25)c (23)a !(23 22 21)c (19)a (19 18 17)c (19 18 17 16)d (15)a