web_synchronization_tool/lib/windows/code.dart

37 lines
981 B
Dart
Raw Normal View History

2024-04-03 14:36:36 +08:00
// 定义密钥
2024-04-03 17:45:52 +08:00
import 'dart:convert';
2024-04-03 14:36:36 +08:00
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);
2024-04-03 17:45:52 +08:00
int decryptedCharCode = (((charCode - 1) ^ key) ^ key2) - key;
return String.fromCharCode(decryptedCharCode);
2024-04-03 14:36:36 +08:00
}
// 加密
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;
}
// 解密
2024-04-03 17:45:52 +08:00
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);
2024-04-03 14:36:36 +08:00
}
2024-04-03 17:45:52 +08:00
return String.fromCharCodes(pstr);
2024-04-03 14:36:36 +08:00
}