web_synchronization_tool/lib/windows/code.dart

37 lines
981 B
Dart

// 定义密钥
import 'dart:convert';
List skey = [8, 1, 2, 5, 4];
// 单个字符异或运算
String makecodeChar(String c, int key, int key2) {
int charCode = c.codeUnitAt(0);
charCode = (((charCode + key) ^ key2) ^ key) + 1;
return String.fromCharCode(charCode);
}
// 单个字符解密
String cutcodeChar(String c, int key, int key2) {
int charCode = c.codeUnitAt(0);
int decryptedCharCode = (((charCode - 1) ^ key) ^ key2) - key;
return String.fromCharCode(decryptedCharCode);
}
// 加密
String makecode(String pstr, List pkey) {
String pp = pstr;
for (int i = 0; i < pp.length; i++) {
pp = pp.replaceRange(i, i + 1, makecodeChar(pp[i], pkey[i % 5], pkey[(i + 18) % 5]));
}
return pp;
}
// 解密
String cutecode(List<int> pstr) {
int len = pstr.length;
for (int i = 0; i < len; i++) {
pstr[i] = cutcodeChar(String.fromCharCode(pstr[i])
, skey[i % 5], skey[(i + 18) % 5]).codeUnitAt(0);
}
return String.fromCharCodes(pstr);
}