The line in base85 I took from the original article .

import base64 text = r'''<~9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!, O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKY i(DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIa l(DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G >uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c~>''' print(base64.b85decode(text.encode())) 

Encoding that text creates base85, very different from the fitting room:

 text = 'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.' text = base64.b85encode(text.encode()).decode() print(text) 

Base85 encoding result:

 O<`^zX>%ZCX>)XGZfA9Ab7*B`EFf-gbRchTY<VDJc_3(Mb0BhMVRLV8EFfZabRc4RAarPHb0BkRZfA9DVR9gFVRLh7Z*CxFa&K)QZ**v7av))DX>DO_b1WctXlY|;AZc?TVIXXEb95kYW*~HEWgu;7Ze%PVbZB98AYyqSVIXj2a&u*NWpZI|V`U(3W*}r`Y-wj`bRcPNAarPDAY*TCbZKsNWn>^>Ze$>7Ze(R<VRUI{VPb4$AZKN6WpZJ3X>V>IZ)PBCZf|#NWn^b%EFfigV`XJzb0BnRWgv5CZ*p`Xc4cT~ZDnp_Wgu^6AYpEKAY);2ZeeU7aBO8^b9HiME& 

If you encode and decode only by means of the base64 module, then there are no problems

  • And what alphabets are used for encoding and decoding? - Vladimir Martyanov
  • The default is utf-8 - gil9red
  • Well, let's say, we figured out the encoding. And what alphabets? - Vladimir Martyanov
  • @ Vladimir _b85alphabet = (b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" b"abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_ , from the module: _b85alphabet = (b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" b"abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_ {{|} ~") - g _b85alphabet = (b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" b"abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_
  • And in the Wiki example, is it? - Vladimir Martyanov

1 answer 1

A careful reading of the wikipedia and documentation for the base64 module makes it base64 that:

  • Base85 and Ascii85 are different things.

  • Ascii85 is also different, and in this example it is its Adobe version ( <~ at the beginning and ~> at the end)


 >>> print(base64.a85decode(text.encode(), adobe=True)) b'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.' 

 >>> print(base64.a85decode(text[2:-2].encode())) b'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.' 

Coding is also fine:

 >>> source_text = 'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.' >>> print(base64.a85encode(source_text.encode(), adobe=True) == text.replace('\n', '').encode()) True 
  • Thanks for the answer, you're right, I was embarrassed by the phrase "...Ascii85, also called Base85..." , so I decided that this was the same thing - gil9red
  • @ gil9red there is an assumption that it is a cant in Wikipedia that needs to be corrected) But I didn’t deal with these encodings, I don’t know their history and will refrain from any actions - andreymal