Files
SimpleRemoter/common/ip_enc.h
2025-05-27 04:15:35 +08:00

34 lines
641 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <vector>
#include <cstdint>
#include <string>
// Encode for IP and Port.
// provided by ChatGPT.
class StreamCipher {
private:
uint32_t state;
// 简单非线性伪随机数生成器
uint8_t prngNext() {
// 例子xorshift32改造一点非线性
state ^= (state << 13);
state ^= (state >> 17);
state ^= (state << 5);
// 再混合一个简单的非线性变换
uint8_t out = (state & 0xFF) ^ ((state >> 8) & 0xFF);
return out;
}
public:
StreamCipher(uint32_t key) : state(key) {}
// 加密解密(对称,长度不变)
void process(uint8_t* data, size_t len) {
for (size_t i = 0; i < len; ++i) {
data[i] ^= prngNext();
}
}
};