From 6b487f58c0098f8c53cfc3a9e00a1ae528651ea1 Mon Sep 17 00:00:00 2001 From: walon Date: Wed, 14 May 2025 14:59:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96float=E5=92=8Cdouble=E5=8A=A0?= =?UTF-8?q?=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/EncryptorBase.cs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/Runtime/EncryptorBase.cs b/Runtime/EncryptorBase.cs index c6ea6af..76264e2 100644 --- a/Runtime/EncryptorBase.cs +++ b/Runtime/EncryptorBase.cs @@ -40,6 +40,28 @@ namespace Obfuz return ((long)decryptedHigh << 32) | (uint)decryptedLow; } + private int? _floatSalt; + + private int GetFloatSalt() + { + if (_floatSalt == null) + { + _floatSalt = Encrypt(0xABCD, 0x12345678, 0); + } + return _floatSalt.Value; + } + + private long? _doubleSalt; + + private long GetDoubleSalt() + { + if (_doubleSalt == null) + { + _doubleSalt = Encrypt(0xAABBCCDDL, 0x12345678, 0); + } + return _doubleSalt.Value; + } + public virtual float Encrypt(float value, int opts, int salt) { if (float.IsNaN(value) || float.IsInfinity(value)) @@ -47,7 +69,7 @@ namespace Obfuz return value; } ref int intValue = ref UnsafeUtility.As(ref value); - int xorValue = ((1 << 23) - 1) & (opts ^ salt); + int xorValue = ((1 << 23) - 1) & (opts ^ salt ^ GetFloatSalt()); intValue ^= xorValue; return value; } @@ -59,7 +81,7 @@ namespace Obfuz return value; } ref int intValue = ref UnsafeUtility.As(ref value); - int xorValue = ((1 << 23) - 1) & (opts ^ salt); + int xorValue = ((1 << 23) - 1) & (opts ^ salt ^ GetFloatSalt()); intValue ^= xorValue; return value; } @@ -71,7 +93,7 @@ namespace Obfuz return value; } ref long longValue = ref UnsafeUtility.As(ref value); - long xorValue = ((1L << 52) - 1) & (((long)opts << 32) | (uint)salt); + long xorValue = ((1L << 52) - 1) & ((((long)opts << 32) | (uint)salt) ^ GetDoubleSalt()); longValue ^= xorValue; return value; } @@ -83,7 +105,7 @@ namespace Obfuz return value; } ref long longValue = ref UnsafeUtility.As(ref value); - long xorValue = ((1L << 52) - 1) & (((long)opts << 32) | (uint)salt); + long xorValue = ((1L << 52) - 1) & ((((long)opts << 32) | (uint)salt) ^ GetDoubleSalt()); longValue ^= xorValue; return value; }