FLUTTER ECOSYSTEM

google/crclib.dart

google/crclib.dart open-source repository details.

crclib.dart 프로젝트 이미지
Stars
22
Forks
19
최근 푸시(UTC)
2021. 12. 9.
프로젝트 상태
보관됨
Google GitHub avatar
GITHUB Organization

Google ↗

Google ❤️ Open Source

United States of America공식 웹사이트 ↗
언어Dart

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 6 개
  • meta>=1.3.0 <2.0.0
  • tuple>=2.0.0 <3.0.0
  • benchmark_harness개발 의존성>=1.0.0 <2.0.0
  • path개발 의존성>=1.8.0 <2.0.0
  • pedantic개발 의존성^1.9.0
  • test개발 의존성>=0.16.0 <2.0.0

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

Dart crclib

This is not an official Google product.

Generic CRC calculations as Dart converters and some common algorithms.

To calculate the CRC value of any message

The easiest way to use this library is to call convert on the instance of the desired CRC routine.

  Crc32Xz().convert(utf8.encode('123456789')) == 0xCBF43926

Another supported use case is as stream transformers.

  File(...).openRead().transform(Crc32Xz()).single.then(...)

Instead of using predefined classes, it is also possible to construct a customized CRC function with ParametricCrc class. For a list of known CRC routines, check out https://reveng.sourceforge.io/crc-catalogue/all.htm.

TODO:

  1. inputReflected and outputReflected can be different, see CRC-12/UMTS.
  2. Bit-level checksums (including non-multiple-of-8 checksums).

To flip bits to obtain desired CRC values

With CrcFlipper, one can call flipWithData or flipWithValue depending on whether they have access to the message, or only its calculated CRC value. The snippet below is taken from test/flipper_test.dart.

      var inputMessage =
          'flipping lowercases to uppercases like mama pig making hot pancakes '
          'for daddy pig in peppa pig cartoon';
      // Mark the lower/upper-case bit in each character.
      // 0x61 = 'a' = 0110 0001
      //                | <-- 5th bit, zero-indexed
      // 0x41 = 'A' = 0100 0001
      var positions = inputMessage.codeUnits
          .asMap()
          .entries
          .where((e) => e.value >= 0x61 && e.value < 0x61 + 26)
          .map((e) => e.key * 8 + 5)
          .toSet();
      var flipper = CrcFlipper(Crc64());
      var solution = flipper.flipWithData(inputMessage.codeUnits, positions,
          CrcValue(BigInt.parse('DEADBEEFCAFEBABE', radix: 16)))!;
      var tmp = List.of(inputMessage.codeUnits, growable: false);
      solution.forEach((bitPosition) {
        var mask = 1 << (bitPosition % 8);
        tmp[bitPosition ~/ 8] ^= mask;
      });
      var outputMessage = String.fromCharCodes(tmp);
      expect(
          outputMessage,
          'flIPpiNG LOWErcAsEs To uPpERcaseS LIkE mAmA Pig mAKInG hOT paNcAKEs '
          'For DAdDY pig in peppa pig cartoon');

The detailed algorithm is documented in flipping_algorithm.md.