Skip to content

Commit

Permalink
Merge pull request #2 from JosepeDev/ver0-7-0
Browse files Browse the repository at this point in the history
Update 0-7-0 content
  • Loading branch information
jozzzzep authored Nov 24, 2020
2 parents 5b58730 + cd78234 commit 860cebd
Show file tree
Hide file tree
Showing 9 changed files with 748 additions and 116 deletions.
Binary file modified Benchmark/VariableEncryption.dll
Binary file not shown.
19 changes: 16 additions & 3 deletions EncTypes/EncBool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ public struct EncBool
#region Variables And Properties

readonly bool _value;
bool Value

public bool Value
{
get => Decrypt(_value);
}

public static string FalseString { get => Boolean.FalseString; }
public static string TrueString { get => Boolean.TrueString; }

#endregion

#region Constructors
Expand All @@ -34,7 +38,16 @@ static bool Decrypt(bool boolVar)
{
return !boolVar;
}


public int CompareTo(Boolean value) => Value.CompareTo(value);
public int CompareTo(object obj) => Value.CompareTo(obj);
public Boolean Equals(Boolean obj) => Value.Equals(obj);
public override Boolean Equals(object obj) => Value.Equals(obj);
public override int GetHashCode() => Value.GetHashCode();
public TypeCode GetTypeCode() => Value.GetTypeCode();
public override string ToString() => Value.ToString();
public string ToString(IFormatProvider provider) => Value.ToString(provider);

#endregion

#region Operators Overloading
Expand All @@ -49,4 +62,4 @@ static bool Decrypt(bool boolVar)
public static implicit operator bool(EncBool eint1) => eint1._value;

#endregion
}
}
159 changes: 145 additions & 14 deletions EncTypes/EncDecimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public struct EncDecimal
/// In the memory it is saved as a different that is affected by random values. { encryptionKey1 & encryptionKey2 }
/// Every time the value changes, the encryption keys change too. And it works exactly as an deciaml.
///
/// Wiki page: https://github.com/JosepeDev/VarEnc/wiki
/// WIKI & INFO: https://github.com/JosepeDev/VarEnc

#region Variables And Properties

Expand All @@ -18,7 +18,7 @@ public struct EncDecimal
private decimal encryptedValue;

// The decrypted value
private decimal Value
public decimal Value
{
set
{
Expand All @@ -30,6 +30,12 @@ private decimal Value
}
}

public Decimal MaxValue { get => Decimal.MaxValue; }
public Decimal MinValue { get => Decimal.MinValue; }
public Decimal MinusOne { get => Decimal.MinusOne; }
public Decimal One { get => Decimal.One; }
public Decimal Zero { get => Decimal.Zero; }

#endregion

#region Methods
Expand All @@ -47,7 +53,7 @@ private static EncDecimal NewEncDecimal(decimal value)

// Encryption key generator
static private Random random = new Random();
public static decimal GetEncryptionKey() => (decimal)(random.NextDouble());
static private decimal GetEncryptionKey() => (decimal)(random.NextDouble());

// Takes a given value and returns it encrypted
private decimal Encrypt(decimal value)
Expand All @@ -67,47 +73,172 @@ private decimal Decrypt(decimal value)
return valueToReturn;
}

// Returns the stored value as a string
public override string ToString()
{
return (Value).ToString();
}
// Overrides
public int CompareTo(Decimal value) => Value.CompareTo(value);
public int CompareTo(object value) => Value.CompareTo(value);
public bool Equals(Decimal value) => Value.Equals(value);
public override bool Equals(object value) => Value.Equals(value);
public override int GetHashCode() => Value.GetHashCode();
public TypeCode GetTypeCode() => Value.GetTypeCode();
public string ToString(string format) => Value.ToString(format);
public string ToString(IFormatProvider provider) => Value.ToString(provider);
public override string ToString() => Value.ToString();
public string ToString(string format, IFormatProvider provider) => Value.ToString(format, provider);

#endregion

#region Operators Overloading

/// + - * / %

public static EncDecimal operator +(EncDecimal eint1, EncDecimal eint2) => EncDecimal.NewEncDecimal(eint1.Value + eint2.Value);
public static EncDecimal operator -(EncDecimal eint1, EncDecimal eint2) => EncDecimal.NewEncDecimal(eint1.Value - eint2.Value);
public static EncDecimal operator *(EncDecimal eint1, EncDecimal eint2) => EncDecimal.NewEncDecimal(eint1.Value * eint2.Value);
public static EncDecimal operator /(EncDecimal eint1, EncDecimal eint2) => EncDecimal.NewEncDecimal(eint1.Value / eint2.Value);
public static EncDecimal operator %(EncDecimal eint1, EncDecimal eint2) => EncDecimal.NewEncDecimal(eint1.Value % eint2.Value);

public static decimal operator +(EncDecimal edecimal1, ulong edecimal2) => edecimal1.Value + edecimal2;
public static decimal operator -(EncDecimal edecimal1, ulong edecimal2) => edecimal1.Value - edecimal2;
public static decimal operator *(EncDecimal edecimal1, ulong edecimal2) => edecimal1.Value * edecimal2;
public static decimal operator /(EncDecimal edecimal1, ulong edecimal2) => edecimal1.Value / edecimal2;
public static decimal operator %(EncDecimal edecimal1, ulong edecimal2) => edecimal1.Value % edecimal2;

public static decimal operator +(EncDecimal edecimal1, long edecimal2) => edecimal1.Value + edecimal2;
public static decimal operator -(EncDecimal edecimal1, long edecimal2) => edecimal1.Value - edecimal2;
public static decimal operator *(EncDecimal edecimal1, long edecimal2) => edecimal1.Value * edecimal2;
public static decimal operator /(EncDecimal edecimal1, long edecimal2) => edecimal1.Value / edecimal2;
public static decimal operator %(EncDecimal edecimal1, long edecimal2) => edecimal1.Value % edecimal2;

public static decimal operator +(EncDecimal edecimal1, uint edecimal2) => edecimal1.Value + edecimal2;
public static decimal operator -(EncDecimal edecimal1, uint edecimal2) => edecimal1.Value - edecimal2;
public static decimal operator *(EncDecimal edecimal1, uint edecimal2) => edecimal1.Value * edecimal2;
public static decimal operator /(EncDecimal edecimal1, uint edecimal2) => edecimal1.Value / edecimal2;
public static decimal operator %(EncDecimal edecimal1, uint edecimal2) => edecimal1.Value % edecimal2;

public static decimal operator +(EncDecimal edecimal1, int edecimal2) => edecimal1.Value + edecimal2;
public static decimal operator -(EncDecimal edecimal1, int edecimal2) => edecimal1.Value - edecimal2;
public static decimal operator *(EncDecimal edecimal1, int edecimal2) => edecimal1.Value * edecimal2;
public static decimal operator /(EncDecimal edecimal1, int edecimal2) => edecimal1.Value / edecimal2;
public static decimal operator %(EncDecimal edecimal1, int edecimal2) => edecimal1.Value % edecimal2;

public static decimal operator +(EncDecimal edecimal1, ushort edecimal2) => edecimal1.Value + edecimal2;
public static decimal operator -(EncDecimal edecimal1, ushort edecimal2) => edecimal1.Value - edecimal2;
public static decimal operator *(EncDecimal edecimal1, ushort edecimal2) => edecimal1.Value * edecimal2;
public static decimal operator /(EncDecimal edecimal1, ushort edecimal2) => edecimal1.Value / edecimal2;
public static decimal operator %(EncDecimal edecimal1, ushort edecimal2) => edecimal1.Value % edecimal2;

public static decimal operator +(EncDecimal edecimal1, short edecimal2) => edecimal1.Value + edecimal2;
public static decimal operator -(EncDecimal edecimal1, short edecimal2) => edecimal1.Value - edecimal2;
public static decimal operator *(EncDecimal edecimal1, short edecimal2) => edecimal1.Value * edecimal2;
public static decimal operator /(EncDecimal edecimal1, short edecimal2) => edecimal1.Value / edecimal2;
public static decimal operator %(EncDecimal edecimal1, short edecimal2) => edecimal1.Value % edecimal2;

public static decimal operator +(EncDecimal edecimal1, byte edecimal2) => edecimal1.Value + edecimal2;
public static decimal operator -(EncDecimal edecimal1, byte edecimal2) => edecimal1.Value - edecimal2;
public static decimal operator *(EncDecimal edecimal1, byte edecimal2) => edecimal1.Value * edecimal2;
public static decimal operator /(EncDecimal edecimal1, byte edecimal2) => edecimal1.Value / edecimal2;
public static decimal operator %(EncDecimal edecimal1, byte edecimal2) => edecimal1.Value % edecimal2;

public static decimal operator +(EncDecimal edecimal1, sbyte edecimal2) => edecimal1.Value + edecimal2;
public static decimal operator -(EncDecimal edecimal1, sbyte edecimal2) => edecimal1.Value - edecimal2;
public static decimal operator *(EncDecimal edecimal1, sbyte edecimal2) => edecimal1.Value * edecimal2;
public static decimal operator /(EncDecimal edecimal1, sbyte edecimal2) => edecimal1.Value / edecimal2;
public static decimal operator %(EncDecimal edecimal1, sbyte edecimal2) => edecimal1.Value % edecimal2;

public static decimal operator +(EncDecimal edecimal1, decimal edecimal2) => edecimal1.Value + edecimal2;
public static decimal operator -(EncDecimal edecimal1, decimal edecimal2) => edecimal1.Value - edecimal2;
public static decimal operator *(EncDecimal edecimal1, decimal edecimal2) => edecimal1.Value * edecimal2;
public static decimal operator /(EncDecimal edecimal1, decimal edecimal2) => edecimal1.Value / edecimal2;
public static decimal operator %(EncDecimal edecimal1, decimal edecimal2) => edecimal1.Value % edecimal2;

public static decimal operator +(EncDecimal edecimal1, double edecimal2) => edecimal1.Value + (decimal)edecimal2;
public static decimal operator -(EncDecimal edecimal1, double edecimal2) => edecimal1.Value - (decimal)edecimal2;
public static decimal operator *(EncDecimal edecimal1, double edecimal2) => edecimal1.Value * (decimal)edecimal2;
public static decimal operator /(EncDecimal edecimal1, double edecimal2) => edecimal1.Value / (decimal)edecimal2;
public static decimal operator %(EncDecimal edecimal1, double edecimal2) => edecimal1.Value % (decimal)edecimal2;

public static decimal operator +(EncDecimal edecimal1, float edecimal2) => edecimal1.Value + (decimal)edecimal2;
public static decimal operator -(EncDecimal edecimal1, float edecimal2) => edecimal1.Value - (decimal)edecimal2;
public static decimal operator *(EncDecimal edecimal1, float edecimal2) => edecimal1.Value * (decimal)edecimal2;
public static decimal operator /(EncDecimal edecimal1, float edecimal2) => edecimal1.Value / (decimal)edecimal2;
public static decimal operator %(EncDecimal edecimal1, float edecimal2) => edecimal1.Value % (decimal)edecimal2;

/// == != < >
public static bool operator ==(EncDecimal eint1, decimal eint2) => eint1.Value == eint2;
public static bool operator !=(EncDecimal eint1, decimal eint2) => eint1.Value != eint2;
public static bool operator >(EncDecimal eint1, decimal eint2) => eint1.Value > eint2;
public static bool operator <(EncDecimal eint1, decimal eint2) => eint1.Value < eint2;

public static bool operator ==(EncDecimal eint1, EncDecimal eint2) => eint1.Value == eint2.Value;
public static bool operator !=(EncDecimal eint1, EncDecimal eint2) => eint1.Value != eint2.Value;
public static bool operator <(EncDecimal eint1, EncDecimal eint2) => eint1.Value < eint2.Value;
public static bool operator >(EncDecimal eint1, EncDecimal eint2) => eint1.Value > eint2.Value;

public static bool operator ==(EncDecimal eint1, ulong eint2) => eint1.Value == eint2;
public static bool operator !=(EncDecimal eint1, ulong eint2) => eint1.Value != eint2;
public static bool operator >(EncDecimal eint1, ulong eint2) => eint1.Value > eint2;
public static bool operator <(EncDecimal eint1, ulong eint2) => eint1.Value < eint2;

public static bool operator ==(EncDecimal eint1, long eint2) => eint1.Value == eint2;
public static bool operator !=(EncDecimal eint1, long eint2) => eint1.Value != eint2;
public static bool operator >(EncDecimal eint1, long eint2) => eint1.Value > eint2;
public static bool operator <(EncDecimal eint1, long eint2) => eint1.Value < eint2;

public static bool operator ==(EncDecimal eint1, uint eint2) => eint1.Value == eint2;
public static bool operator !=(EncDecimal eint1, uint eint2) => eint1.Value != eint2;
public static bool operator >(EncDecimal eint1, uint eint2) => eint1.Value > eint2;
public static bool operator <(EncDecimal eint1, uint eint2) => eint1.Value < eint2;

public static bool operator ==(EncDecimal eint1, int eint2) => eint1.Value == eint2;
public static bool operator !=(EncDecimal eint1, int eint2) => eint1.Value != eint2;
public static bool operator >(EncDecimal eint1, int eint2) => eint1.Value > eint2;
public static bool operator <(EncDecimal eint1, int eint2) => eint1.Value < eint2;

public static bool operator ==(EncDecimal eint1, ushort eint2) => eint1.Value == eint2;
public static bool operator !=(EncDecimal eint1, ushort eint2) => eint1.Value != eint2;
public static bool operator >(EncDecimal eint1, ushort eint2) => eint1.Value > eint2;
public static bool operator <(EncDecimal eint1, ushort eint2) => eint1.Value < eint2;

public static bool operator ==(EncDecimal eint1, short eint2) => eint1.Value == eint2;
public static bool operator !=(EncDecimal eint1, short eint2) => eint1.Value != eint2;
public static bool operator >(EncDecimal eint1, short eint2) => eint1.Value > eint2;
public static bool operator <(EncDecimal eint1, short eint2) => eint1.Value < eint2;

public static bool operator ==(EncDecimal eint1, byte eint2) => eint1.Value == eint2;
public static bool operator !=(EncDecimal eint1, byte eint2) => eint1.Value != eint2;
public static bool operator >(EncDecimal eint1, byte eint2) => eint1.Value > eint2;
public static bool operator <(EncDecimal eint1, byte eint2) => eint1.Value < eint2;

public static bool operator ==(EncDecimal eint1, sbyte eint2) => eint1.Value == eint2;
public static bool operator !=(EncDecimal eint1, sbyte eint2) => eint1.Value != eint2;
public static bool operator >(EncDecimal eint1, sbyte eint2) => eint1.Value > eint2;
public static bool operator <(EncDecimal eint1, sbyte eint2) => eint1.Value < eint2;

public static bool operator ==(EncDecimal eint1, decimal eint2) => eint1.Value == eint2;
public static bool operator !=(EncDecimal eint1, decimal eint2) => eint1.Value != eint2;
public static bool operator >(EncDecimal eint1, decimal eint2) => eint1.Value > eint2;
public static bool operator <(EncDecimal eint1, decimal eint2) => eint1.Value < eint2;

public static bool operator ==(EncDecimal eint1, double eint2) => eint1.Value == (decimal)eint2;
public static bool operator !=(EncDecimal eint1, double eint2) => eint1.Value != (decimal)eint2;
public static bool operator >(EncDecimal eint1, double eint2) => eint1.Value > (decimal)eint2;
public static bool operator <(EncDecimal eint1, double eint2) => eint1.Value < (decimal)eint2;

public static bool operator ==(EncDecimal eint1, float eint2) => eint1.Value == (decimal)eint2;
public static bool operator !=(EncDecimal eint1, float eint2) => eint1.Value != (decimal)eint2;
public static bool operator >(EncDecimal eint1, float eint2) => eint1.Value > (decimal)eint2;
public static bool operator <(EncDecimal eint1, float eint2) => eint1.Value < (decimal)eint2;

/// assign

public static implicit operator EncDecimal(decimal value) => EncDecimal.NewEncDecimal(value);
public static implicit operator decimal(EncDecimal eint1) => eint1.Value;
public static explicit operator float(EncDecimal eint1) => (float)eint1.Value;
public static explicit operator double(EncDecimal eint1) => (double)eint1.Value;
public static explicit operator int(EncDecimal eint1) => (int)eint1.Value;
public static explicit operator float(EncDecimal eint1) => (float)eint1.Value;
public static explicit operator ulong(EncDecimal eint1) => (ulong)eint1.Value;
public static explicit operator long(EncDecimal eint1) => (long)eint1.Value;
public static explicit operator uint(EncDecimal eint1) => (uint)eint1.Value;
public static explicit operator int(EncDecimal eint1) => (int)eint1.Value;
public static explicit operator ushort(EncDecimal eint1) => (ushort)eint1.Value;
public static explicit operator short(EncDecimal eint1) => (short)eint1.Value;
public static explicit operator byte(EncDecimal eint1) => (byte)eint1.Value;
public static explicit operator sbyte(EncDecimal eint1) => (sbyte)eint1.Value;

#endregion
}
Loading

0 comments on commit 860cebd

Please sign in to comment.