2025-05-11 19:28:19 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Obfuz.EncryptionVM.Instructions
|
2025-05-07 10:14:15 +08:00
|
|
|
|
{
|
2025-05-11 12:48:53 +08:00
|
|
|
|
public class XorInstruction : EncryptionInstructionBase
|
2025-05-07 10:14:15 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly int _xorValue;
|
|
|
|
|
private readonly int _opKeyIndex;
|
|
|
|
|
|
|
|
|
|
public XorInstruction(int xorValue, int opKeyIndex)
|
|
|
|
|
{
|
|
|
|
|
_xorValue = xorValue;
|
|
|
|
|
_opKeyIndex = opKeyIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
|
|
|
{
|
2025-05-14 11:05:32 +08:00
|
|
|
|
return (value + secretKey[_opKeyIndex] + salt) ^ _xorValue;
|
2025-05-07 10:14:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
|
|
|
{
|
2025-05-14 11:05:32 +08:00
|
|
|
|
return (value ^ _xorValue) - secretKey[_opKeyIndex] - salt;
|
2025-05-07 10:14:15 +08:00
|
|
|
|
}
|
2025-05-11 19:28:19 +08:00
|
|
|
|
|
|
|
|
|
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
|
|
|
{
|
2025-05-14 11:05:32 +08:00
|
|
|
|
lines.Add(indent + $"value = (value + _secretKey[{_opKeyIndex}] + salt) ^ {_xorValue};");
|
2025-05-11 19:28:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
|
|
|
{
|
2025-05-14 11:05:32 +08:00
|
|
|
|
lines.Add(indent + $"value = (value ^ {_xorValue}) - _secretKey[{_opKeyIndex}] - salt;");
|
2025-05-11 19:28:19 +08:00
|
|
|
|
}
|
2025-05-07 10:14:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|