Home > Back-end >  Why is there a mismatch in base85 between Dart and Python?
Why is there a mismatch in base85 between Dart and Python?

Time:10-10

Python code

from base64 import b85decode
from base64 import b85encode
encoded=b85encode(b'Hello, world!!!!')
print(encoded.decode('utf-8'))

Output:

'NM&qnZ!92pZ*pv8At50l'

Dart code

import 'dart:io';
import 'dart:typed_data';
import 'package:base85/base85.dart';

void main() {
  var codec = Base85Codec(Alphabets.z85);
  var encode = codec.encode(Uint8List.fromList('Hello, world!!!!'.codeUnits));
  print(encode);
}

Output:

nm=QNz.92Pz/PV8aT50L

Letter case is swapped between upper and lower, and non-letters are also mapped differently.

I may be missing something.

CodePudding user response:

Because you are not actually using ascii85 in the dart example at all. Compare this (requires pip install zmq):

from zmq.utils import z85
z85.encode(b"Hello, world!!!!")
#  b'nm=QNz.92Pz/PV8aT50L'

z85 and ascii85 are subtly different.

References:

https://rfc.zeromq.org/spec/32/

  • Related