[Question]
  [
### Background
[Bilibili](https://www.bilibili.com/) is a China-based video sharing platform, similar to Nico Nico Douga in Japan, and Youtube around the world.
Since the establishment, Bilibili had been using the *AV code* to reference a video. An AV code is a string of 3 or more characters, starting with `av` and followed by a natural number, like `av82054919`.
However, since 23 March 2020, [Bilibili introduced a new referencing system called the *BV code*](https://www.bilibili.com/blackboard/activity-BV-PC.html). This time, the code is a string of exactly 12 characters, starting with `BV` and followed by 10 alphanumerical characters, like `BV1XJ41157tQ`. Still, users can use both codes to reference a video, and there is a conversion algorithm between the two.
*(For your information, the two examples reference the same video)*
### [The algorithm](https://www.zhihu.com/question/381784377/answer/1099438784)
To convert from AV code to BV code:
1. Remove the `av` part of the AV code.
2. Do a bitwise XOR between the result in step 1 (as a number) and `177451812`.
3. Add `8728348608` to the result in step 2.
4. Convert the result in step 3 to a 6-digit base-58 number with digits `fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF` in place of `0, 1, ..., 57` respectively. Here, `0, I, O, l` are omitted to eliminate ambiguity. Assume the result is `abcdef`.
5. The BV code is then `BV1db4a1c7ef`.
To convert from BV code to AV code:
1. Remove the 1st to 3rd, the 6th, the 8th and the 10th characters. Assume the result is `abcdef`.
2. Rearrange the result in step 1 to `cbdaef`.
3. Treat the result in step 2 as a base-58 number with digits `fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF` in place of `0, 1, ..., 57` respectively. Convert this base-58 number into decimal.
4. Subtract `8728348608` from the result in step 3.
5. Do a bitwise XOR between the result in step 4 and `177451812`.
6. The AV code is then `av` followed by the result in step 5.
### Example
To convert `av82054919` to BV code:
1. Removing `av` from the code results in `82054919`.
2. \$82054919\text{ XOR }177451812=242727971\$
3. \$242727971+8728348608=8971076579\$
4. \$8971076579\_{10} = (13,38,43,6,30,7)\_{58}\$ → `1J5XtQ`
5. Substituting: `BV1[X][J]4[1]1[5]7[t][Q]` → `BV1XJ41157tQ`
To convert `BV1XJ41157tQ` back to AV code:
1. Remove the bracketed numbers: `[BV1]XJ[4]1[1]5[7]tQ` → `XJ15tQ`
2. Rearranging the characters results in `1J5XtQ`.
3. `1J5XtQ` → \$(13,38,43,6,30,7)\_{58} = 8971076579\_{10}\$
4. \$8971076579-8728348608=242727971\$
5. \$242727971\text{ XOR }177451812=82054919\$
6. Prepending `av` to the result, we have `av82054919`.
### Challenge
Write two independent programs or functions, one receiving the AV code as input and outputting the corresponding BV code, and one receiving the BV code as input and outputting the corresponding AV code. Both the prefixes `av` and `BV` are case insensitive, you may choose either upper or lower case to accept or output. Each code should work even without the code from the other.
You may assume that the input for both programs must have a valid format, and the number in its corresponding AV code is between 1 and 2147483647 inclusive.
### Test cases
```
AV code <-> BV code
av82054919 <-> BV1XJ41157tQ
av123456789 <-> BV1yn411L7tG
av1 <-> BV1xx411c7mQ
av2147483647 <-> BV1Fr4k1q7G1
```
You may check your results through this [tool](https://bvtoav.com/) (not developed by me). Click the first button after entering the AV/BV code into the input, then the textbox will show the result.
### Winning condition
The total length of the codes of the two programs (measured in bytes) will be your code length, and since this is a code-golf challenge, the submission with shortest code length for each language wins. No standard loopholes.
  
[Answer]
# [Python 2](https://docs.python.org/2/), 170 + 150 = 320 bytes
### AV to BV, ~~180 179 173~~ 170 bytes:
```
lambda s:"BV1{2}{4}4{5}1{3}7{1}{0}".format(*["fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF"[((int(s[2:])^177451812)+8728348608)/58**i%58]for i in range(6)])
```
[Try it online!](https://tio.run/##PZBtb9MwFIW/91dcBSElZZTacWK3WpHYxorGQOz9pRTJbZzVLHE8281aovz2zkHavt17nnOO5au3blUpvMsnv3cFLxcZBzsODq5Rg9uGtKRJWtTELW1Q2wzbYJBXpuQu7M@C/L7Kzke3Z0cXVyVG28NHk/47eJK1uOMrtnBkY2/0N3Xylf49Ta6n8cP6x@X3n7@@PC@Pg1kYSuVCO8PjefQHUUoSxBCOPjCKWUxYOmTRp4T1@/J9wub@SZAgFRiuHkSYRvNo9w7MWoFbCVhWmYByXTipCwFOlsLCs3QryGSeCyOU81G9drYnS10ZB3Zre11lIZXoWv0@sC6TatwD4PUeLGqYQMl1aJ3xxEi99988sLqQLgz2P34OosibFzX2zjzkdbdp4//UaV3DZOKHHa8ZHiZkhEbgQ@CventCEEqoO@vxGuGYJCllb3CrPDylbtrBV3Gz8eKSll0CI0IJi1NCX@mxIY/oiU7RCw "Python 2 – Try It Online")
### BV to AV, ~~165 158~~ 150 bytes:
```
s=input()
n=0
for i in 6,4,8,3,10,11:n=n*58+"fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF".find(s[i])
print"av"+`n-8728348608^177451812`
```
[Try it online!](https://tio.run/##PVBdT8IwFH3fr7ipL6CT0K1bCxET8QOjaPxE1GgYrJPq1tW2DPDPY1mib/eec@7JOVet7byUwWZWphx6gBDamJ6QamEbTU/22l5WahAgJMQ@8Zkf@rjtY9yVPbkbsT2UvZTpXWd8e3L/WAR4ffyl45/@t6j4czJnU0tW5kmdy4tT@jmMRoPwY3H1cHl9c7ScnaFWJmTaMK/irekpLaRFSYX2JnKf0YCFhMVt9o4pJRFmOJhsXDTP2wG9kGDnHOrAxSK3QuUcrCi4gaWwc0hFlnHNpYW6hvFEoUptwaxNXSYXkm/7uL1lbCpk1wNIKh@mlXtAkaiGsdoxWii/FreMyoVtoIP9Q9RsOnHt67R5UkzTpOsOHchXfFaHcnPdxnn@j@6rScWCdkQ6uAPOCPojPL4gGEfU3npJhYOQRDFl/@RaOnJI7WBL/oGrlQNntNheBJhQwsKY0D/2TJMv/E0H@Bc "Python 2 – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/index.html), 518 465 439 422 420 412 406 402 401 bytes
*-6 bytes thanks to Surculose Sputum. (I didn't know Python could be made that unreadable!)*  
*-4 bytes thanks to Gavin S. Yancey.*  
*-1 yet another byte gone thanks to Surculose Sputum* 
Encode:
```
def s(x):
 b,a=(int(x[2:])^177451812)+8728348608,''
 while b:a+='fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'[b%58];b//=58
 return f'BV1{a[2::2]}4{a[5]}1{a[3]}7{a[1::-1]}'
```
Decode:
```
def z(i):
 i=i[3:5]+i[6:9:2]+i[10:];a,q,m=i[2]+i[1]+i[3]+i[0]+i[4:],0,1
 for c in a[::-1]:q,m=q+m*'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'.index(c),m*58
 return'av'+str((q-8728348608)^177451812)
```
[Try it online!](https://tio.run/##pVFdb5swFH3nV1iVKkwhKQaDHXdMWrc1U9dOa7t13RCTTEIWt4Hw4VKSKb@d2VT9eN/L9b3n3HN17nW5kct14ff9PFuABnYWM0Dq8AiKQsIu9lhi/UaE4ABR5Fk2JR71MQ1d6pimAR6WYpWBlHE7Mhe/1vPLyc3Fh6vvuYc27@/qcHtciTb7yZc0lbhrfpSfitOP5PYsuJ76f@7Pv33@8vXdw@zEjNP9gCZH6eFhFFAD1Jm8rwuwMI@v0V@uPDAv2WGVBclOA36yI@pBjI1QsjMNbX0LhbYuIhH7LEhsEYdsonQqQS5LjrhTObkiHxEdfB1cHTBLHNdBBlisazADogA8HmYzrans/OB/lhuLYp51cGY5@cHLdiZvTbuRNYTV6OWor2/di7xc1xI0m8bQxlaiyLQ3VY8bOReFWhfw1gFpC6KBVXAtSmiNm3IlJNwDb0ZvwZ6l2tLWUz0N5K01iHS1helQlbX@aoXpSSqoLIoe56pE9fS8pZ4b4AmaDBPVr9ycYoQCIi8M3iLPx0FI6DO5KRR5RuRUk09g1ylwRnKt8BAmmPohJk/sSY3vUEWmqP8H) 
A fairly simple solution comprised of parts of [this](https://gist.github.com/ianoxley/865912/e10cb707cda6aac9e9a6b61d846381300e91498c) and [this](https://learnmeabitcoin.com/guide/base58). Can probably be golfed down a lot, when I get the time. I think it is golfed down to a good-enough level now. *And now it works*
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~192~~ ~~164~~ 163 (81+82) [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
**AV to BV - ~~96~~ ~~82~~ 81 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage):**
```
þ•A³ú[•^•2G&©I•+žL¨…lIOм{œ•F
mʒØà\ç×н˜=ˆ§kð€³ä‘λ°Ð‘ç«(вÍè\pÌ•èÅвA"BV1db4a1c7ef"r‡
```
[Try it online](https://tio.run/##yy9OTMpM/f//8L5HDYscD20@vCsayIgDYiN3tUMrPYEM7aP7fA6teNSwLMfT/8Ke4GqgkBtX7qlJh2ccXhBzePnh6Rf2np5je7rt0PLswxseNa0BGrLkUcOMc7sPbTg8Acg4vPzQao0Lmw73Hl4RU3C4B6hdz/Nw64VNjkpOYYYpSSaJhsnmqWlKRY8aFv7/n1hmYWRgamJpaAkA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9TVmmvpPCobZKCkn3l/8P7HjUscjy0@fCuaCAjDoiN3NUOrfQEMrSP7vM5tOJRw7IcT/8Le4KrgUJuXLmnJh2ecXhBzOHlh6df2Ht6ju3ptkPLsw9veNS0BmjIkkcNM87tPrTh8AQg4/DyQ6s1Lmw63Ht4RUzB4R6gdj3Pw60XNjkqOYUZpiSZJBomm6emKRU9alj4X@d/YpmFkYGpiaWhJVdimaGRsYmpmbkFmA3ERoYm5iYWxmYm5gA).
**BV to AV - ~~96~~ 82 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage):**
```
•1ïÓî•S£ιθSƵª.IžL¨…lIOм{œ•F
mʒØà\ç×н˜=ˆ§kð€³ä‘λ°Ð‘ç«(вÍè\pÌ•èÅβ•2G&©I•-•A³ú[•^„avì
```
[Try it online](https://tio.run/##yy9OTMpM/f//UcMiw8PrD08@vA7ICj60@NzOczuCj209tErP8@g@n0MrHjUsy/H0v7CnOhgo78aVe2rS4RmHF8QcXn54@oW9p@fYnm47tDz78IZHTWsObT685FHDjHO7D204PAHIOLz80GqNC5sO9x5eEVNwuAeoXc/zcOu5TUCGkbvaoZWeQIYuEDsCNe6KBjLiHjXMSyw7vOb/f6cwwwgvE0NDU/OSQAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9TVmmvpPCobZKCkn3l/0cNiwwPrz88@fA6ICv40OJzO8/tCD629dAqPc@j@3wOrXjUsCzH0//CnupgoLwbV@6pSYdnHF4Qc3j54ekX9p6eY3u67dDy7MMbHjWtObT58JJHDTPO7T604fAEIOPw8kOrNS5sOtx7eEVMweEeoHY9z8Ot5zYBGUbuaodWegIZukDsCNS4KxrIiHvUMC@x7PCa/zr/ncIMI7xMDA1NzUsCuYCcyjwgx8e8xB3EqagAcpLNc8EybkUm2YaF5u6GAA).
NOTE: The TIO's use `S` with `.I` (convert to character-list and \$n^{th}\$ permutation builtin) instead of `œ` with `è` (get all permutations and index into the list), since generating all permutations is of course way too slow.
### Explanation:
**AV to BV**:
```
þ                     # Only leave digits of the (implicit) input (to remove "av")
 •A³ú[•               # Push compressed integer 177451812
       ^              # Bitwise-XOR the two integers together
        •2G&©I•       # Push compressed integer 8728348608
               +      # Add the two integers together
žL                    # Push builtin string "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210"
  ¨                   # Remove the last character (the "0")
   …lIO               # Push string "lIO"
       м              # Remove those three as well
        {             # Sort the remaining characters in the string
         œ            # Get a list of all permutations of this string
•F\nmʒØà\ç×н˜=ˆ§kð€³ä‘λ°Ð‘ç«(вÍè\pÌ•
                      # Push compressed integer 1563341720558629316384554749509959660779122984425616460522557465911652079492533
 è                    # Index it into the list of permutations:
                      #  "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF"
  Åв                  # Convert the integer to this custom base
    A                 # Push the lowercase alphabet
     "BV1db4a1c7ef"   # Push string "BV1db4a1c7ef"
                   r  # Reverse the three values on the stack
                    ‡ # Transliterate the lowercase alphabet to the base-converted
                      # characters in "BV1db4a1c7ef"
                      # (after which the result is output implicitly)
```
**BV to AV**:
```
•1ïÓî•                # Push compressed integer 32111112
      S               # Convert it to a list of digits: [3,2,1,1,1,1,1,2]
       £              # Split the (implicit) input-string into parts of that size
        ι             # Uninterleave it
         θ            # Only keep the last result
          S           # And convert it to a flattened list of characters
           Ƶª         # Push compressed integer 270
             .I       # And take the 270th 0-based permutation
žL¨…lIOм{œ•F\nmʒØà\ç×н˜=ˆ§kð€³ä‘λ°Ð‘ç«(вÍè\pÌ•è
                      # Same as in the AB to BV conversion above,
 Åβ                   # but the other way around (convert from the custom base to integer)
•2G&©I•-              # Subtract 8728348608
        •A³ú[•^       # Bitwise-XOR it with 177451812
               „avì   # Prepend "av"
                      # (after which the result is output implicitly)
```
[See this 05AB1E tip of mine (section *How to compress large integers?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `•A³ú[•` is `177451812`; `•2G&©I•` is `8728348608`; `•F\nmʒØà\ç×н˜=ˆ§kð€³ä‘λ°Ð‘ç«(вÍè\pÌ•` is `1563341720558629316384554749509959660779122984425616460522557465911652079492533`; `•1ïÓî•` is `32111112`; and `Ƶª` is `270`.
The `1563341720558629316384554749509959660779122984425616460522557465911652079492533` is generated by [this Jelly builtin](https://tio.run/##BcHVDYNQAADAmXD4xAkW3P5wd2eMLtSkSed63DV5190A/D@/LwCgiMbMogKTs90ehm62XfCHmesjD@OKTDb0Wv1JGmSeaFTME5Fy1xxFN@gzFUCcpFlelFXdtP0wTvOybvtxXvdDMyzHC6IkK6qmG6ZlO67nB2EEwQiK4QRJvQ) (minus 1, since Jelly uses 1-based indexing and 05AB1E uses 0-based indexing).
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 191 + 181 = 372 bytes
Saved ~~4~~ ~~5~~ ~~8~~ 15 bytes thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat)!!!
# AV to BV
# [C (gcc)](https://gcc.gnu.org/), ~~224~~ \$\cdots\$ ~~198~~ 191 bytes
```
r[]=L"BV1__4_1_7";e(a,w)long a,w;{w=(strtol(a+2,0,10)^177451812)+8728348608;for(a=6;a--;w/=58)r["6483:;"[a]-48]="fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF"[w%58];wprintf(r);}
```
[Try it online!](https://tio.run/##RVFrT8IwFP3ur2iakLSyhXV0a7HORFQwisa3KE5SJq8BG3aTgYTfjuUl90N7T3vu6T23gdkNguVSNXyvBssvpNmkTdJkULSRNDI8jKMu0ImYZx5KUpXGQyTztmEZxMKfhDHqEE5snOfM5kXKXYuLTqyQ9FwhTVNkBc/hWDWgS3nxSMCG9E3KfQ923uOvh1L9/vzxeWST2dlAub/l7/6k/SZ7vJXSafI6voyuLlhYc16qxe7PzdP17d1pFlRgI8s53BfZWPWjtIMUFovlSPYjhMH8AOgIelIdyom2NIdywm3LoSVSgoYGxC5Sx2V8i9arTSjT3bmUwYXYC7Q2Anom9StKiMPSe03XcBZpWGNpdQOnUw0DNtreVhQdkG9WJTsxPQ6AdKcg9CwRHif933bcQXKCC9t0/RoW@Xy4M7CKnb0azCXAPAEol2AADaB9hb4BWqsNi3@6/q7Nyb7uI4JbwuJgsfwD "C (gcc) – Try It Online")
# BV to AV
# [C (gcc)](https://gcc.gnu.org/), ~~224~~ \$\cdots\$ ~~186~~ 181 bytes
```
char*d="fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF",b;long w;c(char*s){for(w=b=0;b<6;w+=index(d,s["6483:;"[b++]-48])-d)w*=58;printf("av%ld",w-8728348608^177451812);}
```
[Try it online!](https://tio.run/##XZBrT8IwFIa/8yuWJiQt2yId3VosMxEVDKIRL4hOTHbhsgEDNty4hN@OdYAaz4emT8857zlvXXXgurudO7SjgmeC/tvUeyh3WpePzxMNry5GkbGuzv2k92oPmbMgy/hldh02rmjQ1Nv10uDz9unm7v48dWtAcfh4Gg6klLswk4vRpj@NYGo6ZpE7FYOnsumHXm8JPSW2gEFY6ZQDy5HlrkpYF6keSgumzvgs8sNFHwI7yY89oKQqoxorEWYU2QemlOiYYQ3x7W5i@yFE0iYnichm2onVNTeik2lFnZRxGSgCsFYiukHZgbJTw4SKDQxCwZb/Cjh7gWobdxoEY50uWqJc4CoU2KSL@h6XS4EunRyytYiM8JzW8VFMOJegsCEFwnxQif11b9qHdoJODtdsGuKyHBwNfMfRej6W1DNJ/GliBV3Ef/Iu/P9y7JBgPkbvIVDsPwXb3Hb3BQ "C (gcc) – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 208 bytes
## AV code to BV code, 117 bytes:
```
≔⍘"0|7mγη≔Ｉ✂θ²χ¹θ≔⍘⁺⁻｜θη＆θη⍘!,/>#iγ”\`>⊟∨↖κ2¹W«ε➙⊗MιΦ/⁷Aêμ⁵Ｓ⁶Ｄt÷r≔l⪪≦｜⭆±⊗υ↓1↖Þ»χＺ⁹～”θ≔⁺×f⁻⁶Ｌθθθ⭆BV1db4a1c7ef⎇№βι§θ⌕βιι
```
[Try it online!](https://tio.run/##VY9LT4NAFIX3/gocN0MyRkBa2jQxAbRqLVql1kfcDDCFURjKDPRh/O84QBPr4t7FuefcfCdMMA9znNa1LQSNGXSwIH7JKYsh@ADaj5UBpMQqUhJ1dLT3uFiU0E9pSGCBFAMpuiZHlabiz3TwaJZWAnqUye3QckMFeeBNMpGJvWCzqFMa6QDhGJ1dnNAWQV7A8j2Pnoavj5f@c2boO/eL97@dgq7JG04GQWluxcvqhk2urM9pb3F9Hlfe/O5@Zm/CMfhP1yLNaUYEBEv5vqPrI2VKWFwmsFC7Ol1oJmFk45bJwysInIUeBSbWQ4s06TnhDPMddPNK@gKkUBm0y1sWkW1Ta0xlvVZW26WO6hqvB4bWM4f6sD5dp78 "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
≔⍘"0|7mγη
```
Get the constant `177451812` into a variable as we need it twice because we don't have a bitwise XOR builtin.
```
≔Ｉ✂θ²χ¹θ
```
Extract the value in the AV code as a number.
```
≔⍘⁺⁻｜θη＆θη⍘!,/>#iγ”\`>⊟∨↖κ2¹W«ε➙⊗MιΦ/⁷Aêμ⁵Ｓ⁶Ｄt÷r≔l⪪≦｜⭆±⊗υ↓1↖Þ»χＺ⁹～”θ
```
Subtract the bitwise AND from the bitwise OR giving the bitwise XOR, add the offset, then perform custom base conversion using a compressed version of the given string.
```
≔⁺×f⁻⁶Ｌθθθ
```
Pad the string to 6 characters.
```
⭆BV1db4a1c7ef⎇№βι§θ⌕βιι
```
Substitute the characters in the appropriate positions in the BV code.
## BV code to AV code: 91 bytes:
```
≔⍘"0|7mγη≔⁻⍘⭆684921§θ±Ｉι”\`>⊟∨↖κ2¹W«ε➙⊗MιΦ/⁷Aêμ⁵Ｓ⁶Ｄt÷r≔l⪪≦｜⭆±⊗υ↓1↖Þ»χＺ⁹～”⍘!,/>#iγθavＩ⁻｜θη＆θη
```
[Try it online!](https://tio.run/##TY7LbsIwEEX3/YrU3TiSUWsaCAgJKaH0AYR3KVTduIlx3IIhsQkU8e/GEFRxN6O5M3fmhDFJwxVZaO1JyZmAPpF0pFIuGARf4OHgLgGymI2s2K7dXHYCLjbyejMvAVlDUK441SI2GU@9iYjuYIKsLmVEUdggUkFuGyELzD9X0bA6HTyN3pdF/Nf4Tct7P@EZnZG48q2cnfxYv4pW0/3plCYvj2wTjNvdvrcNn4GJX1Peovv6HT9TmkliMPtmoCAgGfhvzr8v3FxtuaS99IQWn47lhiei3DGqae1P8LTlYFxy1UAXssUR "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
≔⍘"0|7mγη
```
Get the constant `177451812` into a variable again.
```
≔⁻⍘⭆684921§θ±Ｉι”\`>⊟∨↖κ2¹W«ε➙⊗MιΦ/⁷Aêμ⁵Ｓ⁶Ｄt÷r≔l⪪≦｜⭆±⊗υ↓1↖Þ»χＺ⁹～”⍘!,/>#iγθ
```
Extract the characters from the appropriate positions of the BV code, perform custom base conversion, and subtract the offset.
```
avＩ⁻｜θη＆θη
```
Print the bitwise XOR prefixed by `av`.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 322 bytes
```
f=(s,[a,b,c,d,e,f]=(g=n=>n?g(n/58|0)+'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'[n%58]:'')((s.slice(2)^177451812)+8728348608))=>'BV1'+d+b+4+a+1+c+7+e+f
F=s=>'av'+([...'315078'].map(n=>'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'.search(s[2-~n])).reduce((x,y)=>x*58+y)-8728348608^177451812)
```
[Try it online!](https://tio.run/##pZFdb9MwFIbv8yt8g2zj1NSJU7uMFDFYi8ZAGx9jUILmJE6XLXW6OCspbPvrxZlU4J7b9zmv9JxzLtVa2awpV@3A1LnebosYWX@u/NTP/NzXfpHEaBGbeGKeL5B5EsnbISaw@Frn78dnJ68@fFoGbPPyqhn93L8u1/qLupBpyzv7efXaHB6Iy6PodBYubt5@fPPu@MWPbArn5lEkk6cQYoQstVWZaRTg70wIHjHJAkykCGTI5WgoMY4ncP@UQZKTlHCiCCMZEUSTwpvG1kG1hgTNKaUwZNFQSJjQpVoh5/s/jtRq1WQXyM6Dwb1JMKaNzm@cKOr8jXPqHkeSbPDgr@k//ttW2xbE4NxTaxkMIz5mY/BsMAFukbNDzlgk2hPHWBDyaCTkH7gxDh6JdtbDXdh1LszEsm8EjAsuwxEXOzpt@BW7FjPmndO2KZcIU7uqyhbBbwbih1NUIJ6Aahc/FCHGXi9Ji7o5UG5P5B4O0gT3o788ALLa2LrStKoXqCc@KJDCPpiiFOM97w7vbX8D "JavaScript (Node.js) – Try It Online")
A simple and stupid solution. Not so creative. But it at least works.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 295 bytes
```
F=t=>'bv1BD4E1C7A9'.replace(/[9-F]/g,c=>'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'[((t.slice(2)^177451812)+8728348608)/58**('0x'+c-9)%58|0])
G=s=>'av'+([7,5,9,4,11,12].map(n=>x=x*58+'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'.search(s[n])|0,x=16717449)|x^177451812)
```
[Try it online!](https://tio.run/##pY9fU5tAFMXf@RT70tndZEO4ZGGXsWTGaMCx2qn9Y20pHTeIESWAsEVs08@egjPp9L2v53fOvefcq1Y1SZ1VelKUN@luF/jan@NVC4tjvoQjcehhs06rXCUpmUbeJIina5b0ltuv5c177@ri@MOnjQ3PRw@1@3PxmLXpF3UnV5p3zefqpDhdivsz5zKcrX@cf3zz9t3hUxLgiBBtNnnWn7TpdxCCOyDBpmMpbDnj0rUknTpyNCLY6vA4mXj0lSO3VkyN0G/636rFYxIJ5jCPcQbAwI7NjapI4c87vxs5cvw//cwmVXVyR5qoiOnWYp0PrgDBuUe33T99dzptNPLRtaFaaVsO98BDrydztLiEq1MO4Ah90TOwZ9xxhfwLn4sengkdDnAvdl0vJmIzJGzggsuZy8WeBjV/gEcRgnFt6jrbEGo2VZ5pgr8VmL6Mz5E/R/lefgliSo2hpHlb1kvVTyKRYmgV08H6y0AoKYumzFMzL9dkIAwFRFGGQrKi9MD4TQ92fwA "JavaScript (Node.js) – Try It Online")
Thank Arnauld for -7 bytes
[Answer]
# perl -pl (+ bc), 186 + 189 = 375 182 + 187 = 369 bytes
## AV to BV
```
s/^..//;@_=(split//,fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF)[`echo "obase=58;@{[($_^177451812)+8728348608]}"|bc`=~/\d+/g];$_="BV1$_[3]$_[1]4$_[0]1$_[2]7$_[4]$_[5]"
```
[Try it online!](https://tio.run/##HchbT4MwGMbxez@FIVxsma60fUtLCMmcx@g0HucBOwYMNxTXbiCe/ehW5sXzy5O/zpYFM6ZEo24XIb8XBa1SF3mF0MbDnZqcezdnOxdXzwS/bz8t3Y/@Iq@z23gmkgreymt9MD/c5Y8DNtyn05fjy6OT063XdK8djrN0ptYtlcRlFjDh9z7Dlh2NMOfAsMCk3RGcCArCdYT8tr6SdBz8oPtJB02lb0eB1R9iOwqpbMASGh25CkTyRlhlJi1j4loQh4GHvbW4xoQCc7n4/80IBg6CusB/la5yNS/Npi7@AA "Perl 5 – Try It Online")
This uses `bc` to do the decimal to base-58 conversion.
## BV to AV
```
$n=$x=0;%_=map{$_=>$x++}split//,fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF;@y=@_{/1(.)(.)4(.)1(.)7(.)(.)/};$n=58*$n+$_ for@y[2,1,3,0,4,5];$_=av.(($n-8728348608)^177451812)
```
[Try it online!](https://tio.run/##Jc7dToNAEAXge5/CizUB2RYGdrtrCAarFlOrsf7UqlGCtVVaWLaAFWz66uJWk5nkfJmLM3KaJ7RpkPBQ5VnuXuilkVyj0DtElWFsCpnEpWni2WP2dn0wHp7c3KU21MeLvPPdXcar6UP0wV9LUhX38kz0T9l8QEeB8/55cXt@eXX0Nem5fu354doEra2rIWq3kf3T3LiqmvJ9JAwU7s6y3K@fbAzYwRYmmD676pVo1dY0JFqc2dwhvGNx/QUYIxQ42HrTdEcw7hMAysrhjkItFAasDLaoKoUJS/8uvZwsYMkC@MlkGWeiaFoy@QU "Perl 5 – Try It Online")
If you have only 1 line of input, the first 8 bytes can be removed.
Update: Removed 4 + 2 = 6 bytes, because you don't need to quote the strings.
[Answer]
# [Prolog](https://github.com/mthom/scryer-prolog), 725 bytes
```
:-use_module(library(clpz)).                                                   
:-use_module(library(lists)). 
v(A,B):-var(A),var(B).
d(N,D):-v(N,D),!.
d(N,D):-nth0(N,"0123456789",D).
e(N,D):-v(N,D),!.
e(N,D):-nth0(N,"fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF",D).
b(0,_,[0]).
b(1,_,[1]).
b(A,B,C):-A#>1,E#>=0,L#=E+1,(nonvar(C),length(C,L);nonvar(A)),A#<B^(E+1),A#>=B^E,labeling([down],[E]),length(C,L),reverse(C,F),c(A,B,F).
c(0,_,[]).                                         
c(A,B,[C|D]):-A#>0,C#>=0,C#=<B,E#>=0,C#=A mod B,E#=A//B,c(E,B,D).
a([a,v|A],['B','V','1',E,C,'4',B,'1',D,'7',F,G]):-H=[B,C,D,E,F,G],I=177451812,J=8728348608,K#>=0,L#>=0,K#=L xor I+J,L#=(K-J)xor I,O in 1..9,indomain(O),length(A,O),maplist(d,M,A),maplist(e,N,H),b(L,10,M),b(K,58,N),label([L,K]),maplist(d,M,A),maplist(e,N,H).
```
Clear version:
```
:- use_module(library(clpz)).
:- use_module(library(lists)).
v(A, B) :- var(A), var(B).
% Base 10.
d(N, D) :- v(N, D), !. % Keep variable.
d(N, D) :-
    nth0(N, "0123456789", D).
% Base 58.
e(N, D) :- v(N, D), !. % Keep variable.
e(N, D) :-
    nth0(N, "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF", D).
% Base conversion. Base B, Number A, Array C.
b(0, _, [0]).
b(1, _, [1]).
b(A, B, C) :-
    A #> 1,
    nonvar(B),
    E #>= 0,
    L #= E + 1,
    (   nonvar(C), length(C, L)
    ;   nonvar(A)
    ),
    A #< B ^ (E + 1),
    A #>= B ^ E,
    labeling([down], [E]),
    length(C, L),
    reverse(C, F),
    c(A, B, F).
% Required for b.
c(0, _, []).
c(A, B, [C|D]) :-
    A #> 0,
    C #>= 0,
    C #=< B,
    E #>= 0,
    C #= A mod B,
    E #= A // B,
    c(E, B, D).
% Bidirectional decoder.
a([a, v|A], ['B', 'V', '1', E, C, '4', B, '1', D, '7', F, G]) :-
    H = [B, C, D, E, F, G],
    I = 177451812,
    J = 8728348608,
    K #>= 0,
    L #>= 0,
    K #= L xor I + J,
    L #= (K - J) xor I,
    O in 1..9,
    indomain(O),
    length(A, O),
    maplist(d, M, A),
    maplist(e, N, H),
    b(L, 10, M),
    b(K, 58, N),
    label([L, K]),
    maplist(d, M, A),
    maplist(e, N, H).
```
]