Skip to content

Instantly share code, notes, and snippets.

@TesteurManiak
Created May 14, 2024 15:40
Show Gist options
  • Select an option

  • Save TesteurManiak/549a6f97bf864a7ab7426918cbfe7e35 to your computer and use it in GitHub Desktop.

Select an option

Save TesteurManiak/549a6f97bf864a7ab7426918cbfe7e35 to your computer and use it in GitHub Desktop.
Dart version of the Tachiyomi algorithm used to generate source ids.
import 'dart:convert';
import 'dart:math';
import 'package:crypto/crypto.dart';
int generateId(String name, String lang, int versionId) {
String key = "${name.toLowerCase()}/$lang/$versionId";
List<int> bytes = md5.convert(utf8.encode(key)).bytes;
int result = 0;
for (int i = 0; i < 8; i++) {
result |= (bytes[i] & 0xff) << (8 * (7 - i));
}
return result & (pow(2, 63).toInt() - 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment