obfuz/Editor/EncryptionVM/Instructions/AddInstruction.cs

36 lines
1.1 KiB
C#
Raw Permalink Normal View History

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 AddInstruction : EncryptionInstructionBase
2025-05-07 10:14:15 +08:00
{
private readonly int _addValue;
private readonly int _opKeyIndex;
public AddInstruction(int addValue, int opKeyIndex)
{
_addValue = addValue;
_opKeyIndex = opKeyIndex;
}
public override int Encrypt(int value, int[] secretKey, int salt)
{
return ((value + secretKey[_opKeyIndex]) ^ salt) + _addValue;
2025-05-07 10:14:15 +08:00
}
public override int Decrypt(int value, int[] secretKey, int salt)
{
return ((value - _addValue) ^ salt) - secretKey[_opKeyIndex];
2025-05-07 10:14:15 +08:00
}
public override void GenerateEncryptCode(List<string> lines, string indent)
{
lines.Add(indent + $"value = ((value + _secretKey[{_opKeyIndex}]) ^ salt) + {_addValue};");
}
public override void GenerateDecryptCode(List<string> lines, string indent)
{
lines.Add(indent + $"value = ((value - {_addValue}) ^ salt) - _secretKey[{_opKeyIndex}];");
}
2025-05-07 10:14:15 +08:00
}
}