当前位置: 代码迷 >> 综合 >> flutter,rc4加解密
  详细解决方案

flutter,rc4加解密

热度:56   发布时间:2023-12-12 03:29:25.0
class RC4 {static String key = '123456';static List<int> base(List<int> input, String pass) {var output = <int>[];var mBox = GetKey(utf8.encode(pass), 256);// 加密var i = 0;var j = 0;for (var offset = 0; offset < input.length; offset++) {i = (i + 1) % mBox.length;j = (j + ((mBox[i] + 256) % 256)) % mBox.length;var temp = mBox[i];mBox[i] = mBox[j];mBox[j] = temp;var a = input[offset];var b = mBox[(toInt(mBox[i]) + toInt(mBox[j])) % mBox.length];output.insert(offset, a ^ b);}return output;}static List<int> decode(List<int> input, String pass) {return base(input, pass);}static List<int> encode(List<int> input, String pass) {return base(input, pass);}static List<int> GetKey(List<int> pass, int kLen) {var mBox = <int>[];for (var i = 0; i < kLen; i++) {mBox.add(i);}var j = 0;for (var i = 0; i < kLen; i++) {j = (j + ((mBox[i] + 256) % 256) + pass[i % pass.length]) % kLen;var temp = mBox[i];mBox[i] = mBox[j];mBox[j] = temp;}return mBox;}}