Update ZNI Library
This commit is contained in:
parent
0638f7e642
commit
eeadcb1959
10 changed files with 753 additions and 388 deletions
|
@ -51,7 +51,7 @@ namespace LibZNI.Serialization.ZNIFile
|
|||
|
||||
public override void SkipTag(BinaryReader br)
|
||||
{
|
||||
_ = new BoolTag().ReadTag(br);
|
||||
_ = new ByteArrayTag().ReadTag(br);
|
||||
}
|
||||
|
||||
public override void WriteData(BinaryWriter bw)
|
||||
|
|
|
@ -182,6 +182,15 @@ namespace LibZNI.Serialization.ZNIFile
|
|||
case TagType.STRING:
|
||||
_next = new StringTag();
|
||||
break;
|
||||
case TagType.BYTEARRAY:
|
||||
_next = new ByteArrayTag();
|
||||
break;
|
||||
case TagType.INTARRAY:
|
||||
_next = new IntArrayTag();
|
||||
break;
|
||||
case TagType.LONGARRAY:
|
||||
_next = new LongArrayTag();
|
||||
break;
|
||||
case TagType.END:
|
||||
return true;
|
||||
}
|
||||
|
|
84
Serialization/ZNIFile/IntArrayTag.cs
Normal file
84
Serialization/ZNIFile/IntArrayTag.cs
Normal file
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibZNI.Serialization.ZNIFile
|
||||
{
|
||||
public class IntArrayTag : Tag
|
||||
{
|
||||
private int[] BArrVal;
|
||||
public int[] Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return BArrVal;
|
||||
}
|
||||
}
|
||||
|
||||
public IntArrayTag(string _Name, int[] val)
|
||||
{
|
||||
Name = _Name;
|
||||
BArrVal = val;
|
||||
}
|
||||
public IntArrayTag(int[] boolVal) : this(null, boolVal)
|
||||
{
|
||||
}
|
||||
public IntArrayTag() : this(null, new int[] {}) { }
|
||||
|
||||
public override TagType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return TagType.INTARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ReadTag(BinaryReader br)
|
||||
{
|
||||
Name = br.ReadString();
|
||||
int count = br.ReadInt32();
|
||||
BArrVal = new int[count];
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
BArrVal[i] = br.ReadInt32();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Rename(string old, string newName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SkipTag(BinaryReader br)
|
||||
{
|
||||
_ = new IntArrayTag().ReadTag(br);
|
||||
}
|
||||
|
||||
public override void WriteData(BinaryWriter bw)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void WriteTag(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(((int)Type));
|
||||
bw.Write(Name);
|
||||
bw.Write(Value.Length);
|
||||
|
||||
foreach(int i in Value)
|
||||
{
|
||||
bw.Write(i);
|
||||
}
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new IntArrayTag(Name, Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -142,6 +142,15 @@ namespace LibZNI.Serialization.ZNIFile
|
|||
case TagType.STRING:
|
||||
_next = new StringTag();
|
||||
break;
|
||||
case TagType.BYTEARRAY:
|
||||
_next = new ByteArrayTag();
|
||||
break;
|
||||
case TagType.INTARRAY:
|
||||
_next = new IntArrayTag();
|
||||
break;
|
||||
case TagType.LONGARRAY:
|
||||
_next = new LongArrayTag();
|
||||
break;
|
||||
case TagType.END:
|
||||
return true;
|
||||
}
|
||||
|
|
84
Serialization/ZNIFile/LongArrayTag.cs
Normal file
84
Serialization/ZNIFile/LongArrayTag.cs
Normal file
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibZNI.Serialization.ZNIFile
|
||||
{
|
||||
public class LongArrayTag : Tag
|
||||
{
|
||||
private long[] BArrVal;
|
||||
public long[] Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return BArrVal;
|
||||
}
|
||||
}
|
||||
|
||||
public LongArrayTag(string _Name, long[] val)
|
||||
{
|
||||
Name = _Name;
|
||||
BArrVal = val;
|
||||
}
|
||||
public LongArrayTag(long[] boolVal) : this(null, boolVal)
|
||||
{
|
||||
}
|
||||
public LongArrayTag() : this(null, new long[] {}) { }
|
||||
|
||||
public override TagType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return TagType.LONGARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ReadTag(BinaryReader br)
|
||||
{
|
||||
Name = br.ReadString();
|
||||
int count = br.ReadInt32();
|
||||
BArrVal = new long[count];
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
BArrVal[i] = br.ReadInt64();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Rename(string old, string newName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SkipTag(BinaryReader br)
|
||||
{
|
||||
_ = new LongArrayTag().ReadTag(br);
|
||||
}
|
||||
|
||||
public override void WriteData(BinaryWriter bw)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void WriteTag(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(((int)Type));
|
||||
bw.Write(Name);
|
||||
bw.Write(Value.Length);
|
||||
|
||||
foreach(int i in Value)
|
||||
{
|
||||
bw.Write(i);
|
||||
}
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new LongArrayTag(Name, Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -224,6 +224,32 @@ namespace LibZNI.Serialization.ZNIFile
|
|||
}
|
||||
}
|
||||
}
|
||||
public ulong uLongValue
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
case TagType.ULONG:
|
||||
return (this as uLongTag).Value;
|
||||
default:
|
||||
throw new Exception("Invalid type");
|
||||
}
|
||||
}
|
||||
}
|
||||
public Guid UUIDValue
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
case TagType.UUID:
|
||||
return (this as UUIDTag).Value;
|
||||
default:
|
||||
throw new Exception("Invalid type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void Rename(string old, string newName);
|
||||
|
||||
|
|
|
@ -8,17 +8,21 @@ namespace LibZNI.Serialization.ZNIFile
|
|||
{
|
||||
public enum TagType
|
||||
{
|
||||
FOLDER = 0,
|
||||
STRING = 1,
|
||||
INTEGER = 2,
|
||||
LIST = 3, // List can be any valid Tag Type
|
||||
END = 4, // Present at the end of a folder or list
|
||||
BOOL = 5,
|
||||
FOLDER = 10,
|
||||
STRING = 8,
|
||||
INTEGER = 3,
|
||||
LIST = 9, // List can be any valid Tag Type
|
||||
END = 0, // Present at the end of a folder or list
|
||||
BOOL = 13,
|
||||
DOUBLE = 6,
|
||||
FLOAT = 7,
|
||||
LONG = 8,
|
||||
BYTE = 9,
|
||||
BYTEARRAY = 10,
|
||||
FLOAT = 5,
|
||||
LONG = 4,
|
||||
BYTE = 1,
|
||||
BYTEARRAY = 7,
|
||||
INTARRAY = 11,
|
||||
LONGARRAY=12,
|
||||
ULONG=14,
|
||||
UUID=15,
|
||||
|
||||
|
||||
|
||||
|
|
74
Serialization/ZNIFile/UUIDTag.cs
Normal file
74
Serialization/ZNIFile/UUIDTag.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibZNI.Serialization.ZNIFile
|
||||
{
|
||||
public class UUIDTag : Tag
|
||||
{
|
||||
private Guid LongVal;
|
||||
public Guid Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return LongVal;
|
||||
}
|
||||
}
|
||||
|
||||
public UUIDTag(string _Name, Guid val)
|
||||
{
|
||||
Name = _Name;
|
||||
LongVal = val;
|
||||
}
|
||||
public UUIDTag(Guid _LongVal) : this(null, _LongVal)
|
||||
{
|
||||
}
|
||||
public UUIDTag() : this(null, Guid.Empty) { }
|
||||
|
||||
public override TagType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return TagType.UUID;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ReadTag(BinaryReader br)
|
||||
{
|
||||
Name = br.ReadString();
|
||||
LongVal = Guid.Parse(br.ReadString());
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Rename(string old, string newName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SkipTag(BinaryReader br)
|
||||
{
|
||||
_ = new UUIDTag().ReadTag(br);
|
||||
}
|
||||
|
||||
public override void WriteData(BinaryWriter bw)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void WriteTag(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(((int)Type));
|
||||
bw.Write(Name);
|
||||
|
||||
bw.Write(Value.ToString());
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new UUIDTag(Name, Value);
|
||||
}
|
||||
}
|
||||
}
|
74
Serialization/ZNIFile/ulongTag.cs
Normal file
74
Serialization/ZNIFile/ulongTag.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibZNI.Serialization.ZNIFile
|
||||
{
|
||||
public class uLongTag : Tag
|
||||
{
|
||||
private ulong LongVal;
|
||||
public ulong Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return LongVal;
|
||||
}
|
||||
}
|
||||
|
||||
public uLongTag(string _Name, ulong val)
|
||||
{
|
||||
Name = _Name;
|
||||
LongVal = val;
|
||||
}
|
||||
public uLongTag(ulong _LongVal) : this(null, _LongVal)
|
||||
{
|
||||
}
|
||||
public uLongTag() : this(null, 0) { }
|
||||
|
||||
public override TagType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return TagType.ULONG;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ReadTag(BinaryReader br)
|
||||
{
|
||||
Name = br.ReadString();
|
||||
LongVal = br.ReadUInt64();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Rename(string old, string newName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SkipTag(BinaryReader br)
|
||||
{
|
||||
_ = new uLongTag().ReadTag(br);
|
||||
}
|
||||
|
||||
public override void WriteData(BinaryWriter bw)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void WriteTag(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(((int)Type));
|
||||
bw.Write(Name);
|
||||
|
||||
bw.Write(Value);
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new uLongTag(Name, Value);
|
||||
}
|
||||
}
|
||||
}
|
755
Tools.cs
755
Tools.cs
|
@ -1,16 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace LibZNI
|
||||
{
|
||||
public class Tools
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace LibZNI
|
||||
{
|
||||
public class Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Finds whether the sum can even be calculated!
|
||||
|
@ -75,7 +75,7 @@ namespace LibZNI
|
|||
/// <param name="elements">The list of items to create {sum} from</param>
|
||||
/// <param name="sum">The magical number you want to recreate</param>
|
||||
/// <param name="memo">A memory list to reduce the time taken finding the best way to make the sum!</param>
|
||||
/// <returns>The list of {elements} recursively that can make the sum</returns>
|
||||
/// <returns>The list of {elements} recursively that can make the sum</returns>
|
||||
public static List<int> BestSum(List<int> elements, int sum, Dictionary<int, List<int>> memo)
|
||||
{
|
||||
if (memo != null)
|
||||
|
@ -110,14 +110,14 @@ namespace LibZNI
|
|||
|
||||
memo[sum] = shortestCombo;
|
||||
return shortestCombo;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Finds the shortest possible way to create the sum and returns that list
|
||||
/// </summary>
|
||||
/// <param name="elements">The list of items to create {sum} from</param>
|
||||
/// <param name="sum">The magical number you want to recreate</param>
|
||||
/// <param name="memo">A memory list to reduce the time taken finding the best way to make the sum!</param>
|
||||
/// <returns>The list of {elements} recursively that can make the sum</returns>
|
||||
/// <returns>The list of {elements} recursively that can make the sum</returns>
|
||||
public static List<BigInteger> BestSum(List<BigInteger> elements, BigInteger sum, Dictionary<BigInteger, List<BigInteger>> memo, int recursion=0)
|
||||
{
|
||||
if (memo != null)
|
||||
|
@ -149,22 +149,22 @@ namespace LibZNI
|
|||
|
||||
memo[sum] = shortestCombo;
|
||||
return shortestCombo;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// This function is meant for aiding in attacking the TripleDES encryption for the EDRA algorithm. We intentionally want to break TripleDES since we know for a fact we have one of the correct answers that was used as the encryption key. By doing this, we find the right encryption key with zero knowledge
|
||||
/// </summary>
|
||||
/// <param name="input">The TripleDES byte array we want to blank</param>
|
||||
/// <returns>Zero filled Byte Array</returns>
|
||||
/// <returns>Zero filled Byte Array</returns>
|
||||
public static byte[] MakeBlankKey(byte[] input)
|
||||
{
|
||||
return new byte[input.Length];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is meant for aiding in attacking the TripleDES encryption for the EDRA algorithm. We intentionally want to break TripleDES since we know for a fact that we have one of the solutions. This function will increment the current key. If the attack has completed an exception will be thrown
|
||||
/// </summary>
|
||||
/// <param name="tdes">The key array</param>
|
||||
/// <returns>The next key in sequence</returns>
|
||||
/// <returns>The next key in sequence</returns>
|
||||
public static byte[] IncrementAttackVector(byte[] tdes)
|
||||
{
|
||||
string hstr = Convert.ToHexString(tdes);
|
||||
|
@ -183,116 +183,117 @@ namespace LibZNI
|
|||
hstr = Convert.ToHexString(num.ToByteArray());
|
||||
return Convert.FromHexString(hstr);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006 // Naming Styles
|
||||
public static Int32 getTimestamp()
|
||||
#pragma warning restore IDE1006 // Naming Styles
|
||||
{
|
||||
return int.Parse(DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString());
|
||||
}
|
||||
|
||||
public static string GetOSShortID()
|
||||
{
|
||||
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
bool isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||
bool isMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||
if (isWindows) return "windows";
|
||||
if (isLinux) return "linux";
|
||||
if (isMac) return "osx";
|
||||
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
|
||||
public static string Hash2String(byte[] Hash)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte b in Hash)
|
||||
{
|
||||
sb.Append(b.ToString("X2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string MD5Hash(string ToHash)
|
||||
{
|
||||
byte[] Source = UTF8Encoding.UTF8.GetBytes(ToHash);
|
||||
byte[] Hash = new MD5CryptoServiceProvider().ComputeHash(Source);
|
||||
return Tools.Hash2String(Hash);
|
||||
}
|
||||
|
||||
public static string MD5Hash(byte[] ToHash)
|
||||
{
|
||||
return Tools.Hash2String(new MD5CryptoServiceProvider().ComputeHash(ToHash));
|
||||
}
|
||||
|
||||
public static string SHA256Hash(string ToHash)
|
||||
{
|
||||
SHA256 hasher = SHA256.Create();
|
||||
return Tools.Hash2String(hasher.ComputeHash(UTF8Encoding.UTF8.GetBytes(ToHash)));
|
||||
}
|
||||
|
||||
public static string SHA256Hash(byte[] ToHash)
|
||||
{
|
||||
SHA256 Hasher = SHA256.Create();
|
||||
return Tools.Hash2String(Hasher.ComputeHash(ToHash));
|
||||
#pragma warning restore IDE1006 // Naming Styles
|
||||
{
|
||||
return int.Parse(DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString());
|
||||
}
|
||||
|
||||
public static string userProfileFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
public static string GetOSShortID()
|
||||
{
|
||||
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
bool isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||
bool isMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||
if (isWindows) return "windows";
|
||||
if (isLinux) return "linux";
|
||||
if (isMac) return "osx";
|
||||
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
|
||||
public static string Hash2String(byte[] Hash)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte b in Hash)
|
||||
{
|
||||
sb.Append(b.ToString("X2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string MD5Hash(string ToHash)
|
||||
{
|
||||
byte[] Source = UTF8Encoding.UTF8.GetBytes(ToHash);
|
||||
byte[] Hash = new MD5CryptoServiceProvider().ComputeHash(Source);
|
||||
return Tools.Hash2String(Hash);
|
||||
}
|
||||
|
||||
public static string MD5Hash(byte[] ToHash)
|
||||
{
|
||||
return Tools.Hash2String(new MD5CryptoServiceProvider().ComputeHash(ToHash));
|
||||
}
|
||||
|
||||
public static string SHA256Hash(string ToHash)
|
||||
{
|
||||
SHA256 hasher = SHA256.Create();
|
||||
return Tools.Hash2String(hasher.ComputeHash(UTF8Encoding.UTF8.GetBytes(ToHash)));
|
||||
}
|
||||
|
||||
public static string SHA256Hash(byte[] ToHash)
|
||||
{
|
||||
SHA256 Hasher = SHA256.Create();
|
||||
return Tools.Hash2String(Hasher.ComputeHash(ToHash));
|
||||
}
|
||||
|
||||
public static byte[] SHA256HashBytes(byte[] ToHash)
|
||||
{
|
||||
SHA256 hasher = SHA256.Create();
|
||||
return hasher.ComputeHash(ToHash);
|
||||
}
|
||||
}
|
||||
public static byte[] SHA256HashBytes(string ToHash)
|
||||
{
|
||||
SHA256 hasher = SHA256.Create();
|
||||
return hasher.ComputeHash(UTF8Encoding.UTF8.GetBytes(ToHash));
|
||||
}
|
||||
|
||||
public static string ZHX(string ToHash)
|
||||
{
|
||||
ZHash tmp = new ZHash();
|
||||
tmp.NewKey();
|
||||
tmp.CalculateKey(ToHash);
|
||||
return tmp._key;
|
||||
}
|
||||
|
||||
public static string ZSR(string ToSerialize)
|
||||
{
|
||||
ZHash tmp = new ZHash();
|
||||
tmp.NewSerial();
|
||||
tmp.CalculateKey(ToSerialize);
|
||||
return tmp._key;
|
||||
}
|
||||
|
||||
public static string Base64Encode(string plainText)
|
||||
{
|
||||
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
|
||||
return System.Convert.ToBase64String(plainTextBytes);
|
||||
}
|
||||
public static string Base64Decode(string base64EncodedData)
|
||||
{
|
||||
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
|
||||
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
|
||||
}
|
||||
|
||||
public static string GoUpOneLevel(string path)
|
||||
{
|
||||
string[] paths = path.Split(new[] { '/', '\\' });
|
||||
|
||||
List<string> pathList = paths.ToList();
|
||||
pathList.Remove(pathList[pathList.Count-1]);
|
||||
|
||||
string pathListStr = "";
|
||||
foreach(string s in pathList)
|
||||
{
|
||||
pathListStr += s + "/";
|
||||
}
|
||||
return pathListStr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static string ZHX(string ToHash)
|
||||
{
|
||||
ZHash tmp = new ZHash();
|
||||
tmp.NewKey();
|
||||
tmp.CalculateKey(ToHash);
|
||||
return tmp._key;
|
||||
}
|
||||
|
||||
public static string ZSR(string ToSerialize)
|
||||
{
|
||||
ZHash tmp = new ZHash();
|
||||
tmp.NewSerial();
|
||||
tmp.CalculateKey(ToSerialize);
|
||||
return tmp._key;
|
||||
}
|
||||
|
||||
public static string Base64Encode(string plainText)
|
||||
{
|
||||
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
|
||||
return System.Convert.ToBase64String(plainTextBytes);
|
||||
}
|
||||
public static string Base64Decode(string base64EncodedData)
|
||||
{
|
||||
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
|
||||
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
|
||||
}
|
||||
|
||||
public static string GoUpOneLevel(string path)
|
||||
{
|
||||
string[] paths = path.Split(new[] { '/', '\\' });
|
||||
|
||||
List<string> pathList = paths.ToList();
|
||||
pathList.Remove(pathList[pathList.Count-1]);
|
||||
|
||||
string pathListStr = "";
|
||||
foreach(string s in pathList)
|
||||
{
|
||||
pathListStr += s + "/";
|
||||
}
|
||||
return pathListStr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Format:
|
||||
/// w = week
|
||||
|
@ -302,7 +303,7 @@ namespace LibZNI
|
|||
/// s = second
|
||||
/// </summary>
|
||||
/// <param name="TimeStr"></param>
|
||||
/// <returns></returns>
|
||||
/// <returns></returns>
|
||||
public static TimeSpan DecodeTimeNotation(string TimeStr)
|
||||
{
|
||||
|
||||
|
@ -350,8 +351,8 @@ namespace LibZNI
|
|||
i += 2;
|
||||
}
|
||||
return F;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static int GetUnixDifference(TimeSpan ts)
|
||||
{
|
||||
return (int)ts.TotalSeconds;
|
||||
|
@ -361,17 +362,17 @@ namespace LibZNI
|
|||
/// Encodes a timestamp or difference into ZNI Notation
|
||||
/// </summary>
|
||||
/// <param name="ts"></param>
|
||||
/// <returns>ZNI Time Notation</returns>
|
||||
/// <returns>ZNI Time Notation</returns>
|
||||
public static string EncodeTimeNotation(TimeSpan ts)
|
||||
{
|
||||
return EncodeTimeNotation(GetUnixDifference(ts));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes a unix timestamp or difference into ZNI Notation
|
||||
/// </summary>
|
||||
/// <param name="ts"></param>
|
||||
/// <returns>ZNI Time Notation</returns>
|
||||
/// <returns>ZNI Time Notation</returns>
|
||||
public static string EncodeTimeNotation(int ts)
|
||||
{
|
||||
var ONE_DAY = ((60 * 60) * 24);
|
||||
|
@ -413,114 +414,114 @@ namespace LibZNI
|
|||
X.Add($"s");
|
||||
}
|
||||
return String.Join("", X);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable()]
|
||||
public class ZHash
|
||||
{
|
||||
[JsonRequired(), JsonProperty(PropertyName = "value")]
|
||||
public string _key;
|
||||
[JsonIgnore()]
|
||||
public string _template;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_key = _template;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _key;
|
||||
}
|
||||
|
||||
|
||||
public void NewKey()
|
||||
{
|
||||
|
||||
_key = "".PadLeft(10, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(4, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(6, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(8, '0');
|
||||
|
||||
}
|
||||
|
||||
public void NewSerial()
|
||||
{
|
||||
_key = "".PadLeft(10, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(6, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(4, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(4, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(2, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(4, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(8, '0');
|
||||
|
||||
}
|
||||
public void CalculateKey(string K)
|
||||
{
|
||||
string valid = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ=.+/\\][{}';:?><,_-)(*&^%$#@!`~|";
|
||||
while (valid.Length < K.Length)
|
||||
{
|
||||
valid += valid;
|
||||
}
|
||||
StringBuilder tmp = new StringBuilder(_key);
|
||||
|
||||
for (int i = 0; i < _key.Length; i++)
|
||||
{
|
||||
char V = _key[i];
|
||||
if (V != '-')
|
||||
{
|
||||
MD5 MDHash = MD5.Create();
|
||||
for (int ii = 0; ii < ((K.Length > _key.Length) ? _key.Length : K.Length); ii++)
|
||||
{
|
||||
byte[] md5Data = MDHash.ComputeHash(Encoding.UTF8.GetBytes((K + i.ToString() + valid[i].ToString() + valid[ii].ToString()).ToCharArray()));
|
||||
// Replace digit with MD5'd char from String K encoded alongside (i)
|
||||
StringBuilder hashData = new StringBuilder();
|
||||
foreach (byte b in md5Data)
|
||||
{
|
||||
hashData.Append(b.ToString("X2"));
|
||||
}
|
||||
string Hash = hashData.ToString();
|
||||
tmp[i] = Hash[(i > 31 ? 1 : i)];
|
||||
//Console.Write("\r" + tmp.ToString() + "\r");
|
||||
}
|
||||
}
|
||||
}
|
||||
//Console.WriteLine("\r\n");
|
||||
_key = tmp.ToString();
|
||||
}
|
||||
|
||||
public static byte[] HashToBytes(string Key)
|
||||
{
|
||||
return Enumerable.Range(0, Key.Length).Where(x=>x % 2 == 0).Select(x=>Convert.ToByte(Key.Substring(x,2),16)).ToArray();
|
||||
}
|
||||
public static ZHash Bytes2Hash(byte[] key)
|
||||
{
|
||||
ZHash itm = new ZHash();
|
||||
foreach(byte b in key)
|
||||
{
|
||||
itm._key += b.ToString("X2");
|
||||
}
|
||||
itm._template = itm._key;
|
||||
return itm;
|
||||
}
|
||||
|
||||
public static string Bytes2HashStr(byte[] key)
|
||||
{
|
||||
return Bytes2Hash(key)._key;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LinqExtensions
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable()]
|
||||
public class ZHash
|
||||
{
|
||||
[JsonRequired(), JsonProperty(PropertyName = "value")]
|
||||
public string _key;
|
||||
[JsonIgnore()]
|
||||
public string _template;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_key = _template;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _key;
|
||||
}
|
||||
|
||||
|
||||
public void NewKey()
|
||||
{
|
||||
|
||||
_key = "".PadLeft(10, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(4, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(6, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(8, '0');
|
||||
|
||||
}
|
||||
|
||||
public void NewSerial()
|
||||
{
|
||||
_key = "".PadLeft(10, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(6, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(4, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(4, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(2, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(4, '0');
|
||||
_key += "-";
|
||||
_key += "".PadRight(8, '0');
|
||||
|
||||
}
|
||||
public void CalculateKey(string K)
|
||||
{
|
||||
string valid = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ=.+/\\][{}';:?><,_-)(*&^%$#@!`~|";
|
||||
while (valid.Length < K.Length)
|
||||
{
|
||||
valid += valid;
|
||||
}
|
||||
StringBuilder tmp = new StringBuilder(_key);
|
||||
|
||||
for (int i = 0; i < _key.Length; i++)
|
||||
{
|
||||
char V = _key[i];
|
||||
if (V != '-')
|
||||
{
|
||||
MD5 MDHash = MD5.Create();
|
||||
for (int ii = 0; ii < ((K.Length > _key.Length) ? _key.Length : K.Length); ii++)
|
||||
{
|
||||
byte[] md5Data = MDHash.ComputeHash(Encoding.UTF8.GetBytes((K + i.ToString() + valid[i].ToString() + valid[ii].ToString()).ToCharArray()));
|
||||
// Replace digit with MD5'd char from String K encoded alongside (i)
|
||||
StringBuilder hashData = new StringBuilder();
|
||||
foreach (byte b in md5Data)
|
||||
{
|
||||
hashData.Append(b.ToString("X2"));
|
||||
}
|
||||
string Hash = hashData.ToString();
|
||||
tmp[i] = Hash[(i > 31 ? 1 : i)];
|
||||
//Console.Write("\r" + tmp.ToString() + "\r");
|
||||
}
|
||||
}
|
||||
}
|
||||
//Console.WriteLine("\r\n");
|
||||
_key = tmp.ToString();
|
||||
}
|
||||
|
||||
public static byte[] HashToBytes(string Key)
|
||||
{
|
||||
return Enumerable.Range(0, Key.Length).Where(x=>x % 2 == 0).Select(x=>Convert.ToByte(Key.Substring(x,2),16)).ToArray();
|
||||
}
|
||||
public static ZHash Bytes2Hash(byte[] key)
|
||||
{
|
||||
ZHash itm = new ZHash();
|
||||
foreach(byte b in key)
|
||||
{
|
||||
itm._key += b.ToString("X2");
|
||||
}
|
||||
itm._template = itm._key;
|
||||
return itm;
|
||||
}
|
||||
|
||||
public static string Bytes2HashStr(byte[] key)
|
||||
{
|
||||
return Bytes2Hash(key)._key;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LinqExtensions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
@ -581,20 +582,20 @@ namespace LibZNI
|
|||
{
|
||||
i -= bitToSet;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReplaceAtIndex(this string a, int b, string c)
|
||||
{
|
||||
string sSplice = "";
|
||||
if(b == 0)
|
||||
{
|
||||
sSplice = $"{c}{a.Substring(1)}";
|
||||
}else
|
||||
{
|
||||
sSplice = $"{a.Substring(0,b)}{c}{a.Substring(b+1)}";
|
||||
}
|
||||
return sSplice;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReplaceAtIndex(this string a, int b, string c)
|
||||
{
|
||||
string sSplice = "";
|
||||
if(b == 0)
|
||||
{
|
||||
sSplice = $"{c}{a.Substring(1)}";
|
||||
}else
|
||||
{
|
||||
sSplice = $"{a.Substring(0,b)}{c}{a.Substring(b+1)}";
|
||||
}
|
||||
return sSplice;
|
||||
}
|
||||
public static BigInteger GetAtIndex(this List<BigInteger> X, BigInteger I)
|
||||
{
|
||||
BigInteger D = -1;
|
||||
|
@ -604,7 +605,7 @@ namespace LibZNI
|
|||
if (D >= I) return V;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public static int GoesIntoTimes(this BigInteger X, BigInteger Z)
|
||||
{
|
||||
int nTimes = 0;
|
||||
|
@ -622,58 +623,58 @@ namespace LibZNI
|
|||
}
|
||||
|
||||
return nTimes;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class ZNILSLTools
|
||||
{
|
||||
public static bool Compare<T>(this List<string> itx, List<string> itx2)
|
||||
{
|
||||
if (itx.Count != itx2.Count) return false;
|
||||
for(int i = 0; i < itx.Count; i++)
|
||||
{
|
||||
if(itx[i] != itx2[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class ZNILSLTools
|
||||
{
|
||||
public static bool Compare<T>(this List<string> itx, List<string> itx2)
|
||||
{
|
||||
if (itx.Count != itx2.Count) return false;
|
||||
for(int i = 0; i < itx.Count; i++)
|
||||
{
|
||||
if(itx[i] != itx2[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006 // Naming Styles
|
||||
public static List<string> llParseString2List(this string item, string[] opts, string[] keepopts)
|
||||
{
|
||||
return ParseString2List(item, opts, keepopts, false);
|
||||
public static List<string> llParseString2List(this string item, string[] opts, string[] keepopts)
|
||||
{
|
||||
return ParseString2List(item, opts, keepopts, false);
|
||||
}
|
||||
public static List<string> llParseStringKeepNulls(this string item, string[] opts, string[] keepopts)
|
||||
{
|
||||
return ParseString2List(item, opts, keepopts, true);
|
||||
public static List<string> llParseStringKeepNulls(this string item, string[] opts, string[] keepopts)
|
||||
{
|
||||
return ParseString2List(item, opts, keepopts, true);
|
||||
}
|
||||
#pragma warning restore IDE1006 // Naming Styles
|
||||
|
||||
#pragma warning restore IDE1006 // Naming Styles
|
||||
|
||||
#pragma warning disable IDE1006 // Naming Styles
|
||||
public static string llDumpList2String<T>(this List<T> items, string delimiter)
|
||||
#pragma warning restore IDE1006 // Naming Styles
|
||||
{
|
||||
return String.Join(delimiter, items.Select(t => t.ToString()).ToArray());
|
||||
}
|
||||
|
||||
internal static string[] Augment(this string[] itm, string x)
|
||||
{
|
||||
List<string> working = new List<string>(itm);
|
||||
List<string> buffer = new List<string>();
|
||||
for(int i = 0; i < working.Count; i++)
|
||||
{
|
||||
if (String.IsNullOrEmpty(working[i])) break;
|
||||
buffer.Add(working[i]);
|
||||
|
||||
if (i == working.Count - 1) break;
|
||||
else
|
||||
buffer.Add(x);
|
||||
|
||||
}
|
||||
return buffer.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
internal static string[] Augment(this string[] itm, string x)
|
||||
{
|
||||
List<string> working = new List<string>(itm);
|
||||
List<string> buffer = new List<string>();
|
||||
for(int i = 0; i < working.Count; i++)
|
||||
{
|
||||
if (String.IsNullOrEmpty(working[i])) break;
|
||||
buffer.Add(working[i]);
|
||||
|
||||
if (i == working.Count - 1) break;
|
||||
else
|
||||
buffer.Add(x);
|
||||
|
||||
}
|
||||
return buffer.ToArray();
|
||||
}
|
||||
/// <summary>
|
||||
/// This function was partially taken from the OpenSimulator code and modified to no longer be LSL related and purely function the same way for my own sanity's sake
|
||||
///
|
||||
|
@ -681,23 +682,23 @@ namespace LibZNI
|
|||
/// <param name="item"></param>
|
||||
/// <param name="opts"></param>
|
||||
/// <param name="keepopts"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string> ParseString2List(this string item, string[] opts, string[] keepopts, bool keepNulls)
|
||||
{
|
||||
int sourceLen = item.Length;
|
||||
int optionsLength = opts.Length;
|
||||
int spacersLen = keepopts.Length;
|
||||
|
||||
int dellen = 0;
|
||||
string[] delArray = new string[optionsLength + spacersLen];
|
||||
|
||||
int outlen = 0;
|
||||
string[] outArray = new string[sourceLen * 2 + 1];
|
||||
|
||||
int i, j;
|
||||
string d;
|
||||
|
||||
|
||||
/// <returns></returns>
|
||||
public static List<string> ParseString2List(this string item, string[] opts, string[] keepopts, bool keepNulls)
|
||||
{
|
||||
int sourceLen = item.Length;
|
||||
int optionsLength = opts.Length;
|
||||
int spacersLen = keepopts.Length;
|
||||
|
||||
int dellen = 0;
|
||||
string[] delArray = new string[optionsLength + spacersLen];
|
||||
|
||||
int outlen = 0;
|
||||
string[] outArray = new string[sourceLen * 2 + 1];
|
||||
|
||||
int i, j;
|
||||
string d;
|
||||
|
||||
|
||||
for(i=0;i<optionsLength; i++)
|
||||
{
|
||||
d = opts[i].ToString();
|
||||
|
@ -705,10 +706,10 @@ namespace LibZNI
|
|||
{
|
||||
delArray[dellen++] = d;
|
||||
}
|
||||
}
|
||||
optionsLength = dellen;
|
||||
|
||||
|
||||
}
|
||||
optionsLength = dellen;
|
||||
|
||||
|
||||
for (i = 0; i < spacersLen; i++)
|
||||
{
|
||||
d = keepopts[i].ToString();
|
||||
|
@ -716,9 +717,9 @@ namespace LibZNI
|
|||
{
|
||||
delArray[dellen++] = d;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(i=0; ;)
|
||||
{
|
||||
int earliestDel = -1;
|
||||
|
@ -755,68 +756,68 @@ namespace LibZNI
|
|||
outArray[outlen++] = earliestStr;
|
||||
}
|
||||
i = earliestSrc + earliestStr.Length;
|
||||
}
|
||||
|
||||
List<string> outList = new List<string>();
|
||||
}
|
||||
|
||||
List<string> outList = new List<string>();
|
||||
for(i = 0;i<outlen; i++)
|
||||
{
|
||||
outList.Add(outArray[i]);
|
||||
}
|
||||
|
||||
return outList;
|
||||
/*
|
||||
List<string> entries = new List<string>();
|
||||
List<string> tmpBuffer = new List<string>();
|
||||
List<string> buffer = new List<string>();
|
||||
buffer.Add(item);
|
||||
foreach(string x in opts)
|
||||
{
|
||||
for(int i=0;i<buffer.Count;i++)
|
||||
{
|
||||
string y = buffer[i];
|
||||
if (y.Contains(x))
|
||||
{
|
||||
string[] newbufferItem = y.Split(x);
|
||||
foreach (string V in newbufferItem)
|
||||
{
|
||||
tmpBuffer.Add(V);
|
||||
}
|
||||
}
|
||||
else tmpBuffer.Add(y);
|
||||
}
|
||||
buffer = tmpBuffer;
|
||||
tmpBuffer = new List<string>();
|
||||
}
|
||||
|
||||
// Now re-run the buffer through the keep opts list
|
||||
tmpBuffer = new List<string>();
|
||||
foreach(string z in keepopts)
|
||||
{
|
||||
for(int i=0;i<buffer.Count;i++)
|
||||
{
|
||||
string y = buffer[i];
|
||||
if (y.Contains(z))
|
||||
{
|
||||
string[] newbuff = y.Split(z).Augment(z);
|
||||
foreach(string V in newbuff)
|
||||
{
|
||||
tmpBuffer.Add(V);
|
||||
}
|
||||
}else
|
||||
{
|
||||
tmpBuffer.Add(y);
|
||||
}
|
||||
}
|
||||
buffer = tmpBuffer;
|
||||
tmpBuffer = new List<string>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
entries = buffer;
|
||||
buffer = new List<string>();
|
||||
|
||||
return entries;*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return outList;
|
||||
/*
|
||||
List<string> entries = new List<string>();
|
||||
List<string> tmpBuffer = new List<string>();
|
||||
List<string> buffer = new List<string>();
|
||||
buffer.Add(item);
|
||||
foreach(string x in opts)
|
||||
{
|
||||
for(int i=0;i<buffer.Count;i++)
|
||||
{
|
||||
string y = buffer[i];
|
||||
if (y.Contains(x))
|
||||
{
|
||||
string[] newbufferItem = y.Split(x);
|
||||
foreach (string V in newbufferItem)
|
||||
{
|
||||
tmpBuffer.Add(V);
|
||||
}
|
||||
}
|
||||
else tmpBuffer.Add(y);
|
||||
}
|
||||
buffer = tmpBuffer;
|
||||
tmpBuffer = new List<string>();
|
||||
}
|
||||
|
||||
// Now re-run the buffer through the keep opts list
|
||||
tmpBuffer = new List<string>();
|
||||
foreach(string z in keepopts)
|
||||
{
|
||||
for(int i=0;i<buffer.Count;i++)
|
||||
{
|
||||
string y = buffer[i];
|
||||
if (y.Contains(z))
|
||||
{
|
||||
string[] newbuff = y.Split(z).Augment(z);
|
||||
foreach(string V in newbuff)
|
||||
{
|
||||
tmpBuffer.Add(V);
|
||||
}
|
||||
}else
|
||||
{
|
||||
tmpBuffer.Add(y);
|
||||
}
|
||||
}
|
||||
buffer = tmpBuffer;
|
||||
tmpBuffer = new List<string>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
entries = buffer;
|
||||
buffer = new List<string>();
|
||||
|
||||
return entries;*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue