xorCode static method

String xorCode(
  1. String res,
  2. String key
)

异或对称加密(按 UTF-16 码元;自反)。

密钥为逗号分隔的整数;非整数分段抛出 ArgumentError。

Implementation

static String xorCode(String res, String key) {
  final List<int> keyInts = _parseXorKey(key);
  final List<int> codeUnits = res.codeUnits;
  final List<int> codes = [];
  for (int i = 0, length = codeUnits.length; i < length; i++) {
    final int code = codeUnits[i] ^ keyInts[i % keyInts.length];
    codes.add(code);
  }
  return String.fromCharCodes(codes);
}