/// <summary> Decrypts a message </summary> /// <param name="message"> Byte[] to decrypt </param> /// <param name="index"> Index to begin copy from. Negative numbers behave like 0. </param> /// <param name="length"> Length of characters to copy. Negative numbers/0 take the rest of the array. </param> /// <returns> Decrypted copy of byte[] segment </returns> public byte[] Decrypt(byte[] message, int index = -1, int length = -1) { if (index < 0) { index = 0; } if (length < 1) { length = message.Length - index; } byte[] dec = new byte[length]; for (int i = 0; i < length; i++) { byte b = message[index + i]; long hash = SRNG.hash(decPos++); byte encDiff = (byte)hash; byte encKey = (byte)(hash >> 8); b ^= encKey; b -= encDiff; dec[i] = b; if (b == EOT) { decPos = START; } } return(dec); }
/// <summary> Encrypts a message </summary> /// <param name="message"> Byte[] to encrypt </param> /// <param name="index"> Index to begin copy from. Negative numbers behave like 0. </param> /// <param name="length"> Length of Byte[] to copy. Negative numbers/0 take the rest of the array. </param> /// <returns> Encrypted copy of Byte[] segment </returns> public byte[] Encrypt(byte[] message, int index = -1, int length = -1) { if (index < 0) { index = 0; } if (length < 1) { length = message.Length - index; } byte[] enc = new byte[length]; for (int i = 0; i < length; i++) { byte b = (message[index + i]); bool wasEOT = (b == EOT); long hash = SRNG.hash(encPos++); byte encDiff = (byte)hash; byte encKey = (byte)(hash >> 8); b += encDiff; b ^= encKey; enc[i] = b; if (wasEOT) { encPos = START; } } return(enc); }
/// <summary> Decrypts a segment of a Byte[], in place. </summary> /// <param name="message"> Byte[] to decrypt </param> /// <param name="index"> Index to begin decryption at. Negative numbers behave like 0. </param> /// <param name="length"> Length of Byte[] segment to decrypt. Negative numbers/0 encrypt from index to the end. </param> public void DecryptInPlace(byte[] message, int index = -1, int length = -1) { if (index < 0) { index = 0; } if (length < 01) { length = message.Length - index; } for (int i = 0; i < length; i++) { byte b = message[index + i]; long hash = SRNG.hash(decPos++); byte encDiff = (byte)hash; byte encKey = (byte)(hash >> 8); b ^= encKey; b -= encDiff; message[index + i] = b; if (b == EOT) { decPos = START; } } }
/// <summary> Encrypts a segment of a Byte[], in place. </summary> /// <param name="message"> Byte[] to encrypt</param> /// <param name="index"> Index to begin encryption at. Negative numbers behave like 0. </param> /// <param name="length"> Length of Byte[] segment to encrypt. Negative numbers/0 encrypt from index to the end. </param> public void EncryptInPlace(byte[] message, int index = -1, int length = -1) { if (index < 0) { index = 0; } if (length < 1) { length = message.Length - index; } for (int i = 0; i < length; i++) { byte b = message[index + i]; bool wasEOT = (b == EOT); long hash = SRNG.hash(encPos++); byte encDiff = (byte)hash; byte encKey = (byte)(hash >> 8); b += encDiff; b ^= encKey; message[index + i] = b; if (wasEOT) { encPos = START; } } }
public static long[] TEST_GENERATE_SEQUENCE(int size = 512) { long[] vals = new long[size]; long pos = EncDec.START; for (int i = 0; i < size; i++) { pos = SRNG.hash(pos); vals[i] = pos; } return(vals); }
public UberData(int octaves, Ex.Utils.SRNG rng) { this.octaves = octaves; perturb = rng.NextFloat(-.4f, .4f); sharpness = rng.NextFloat(-1f, 1f); amplify = rng.NextFloat(0, .5f); altitudeErosion = rng.NextFloat(0, .25f); ridgeErosion = rng.NextFloat(0, 1.0f); slopeErosion = rng.NextFloat(0, 1.0f); lacunarity = rng.NextFloat(1.1f, 2.5f); gain = rng.NextFloat(.2f, .8f); startAmplitude = rng.NextFloat(0.1f, 3f); scale = rng.NextFloat(.0005f, .0016f); }
public static void RNG_TESTING() { SRNG r = new SRNG(); int numBuckets = 200; int[] buckets = new int[numBuckets]; for (int i = 0; i < 1024 * 1024; i++) { float val = r.NextFloat(0, numBuckets); buckets[(int)val]++; } for (int i = 0; i < buckets.Length; i++) { Debug.Log("Bucket " + i + ": " + buckets[i]); } }
public static void ENCRYPTION_TESTING() { string original = "the goyim know too much" + EOT + "Everything here is make believe, only a fool would take it seriously." + EOT + "Don't worry, it's just fake news" + EOT + "SPIRIT COOKING" + EOT + "its like annudah shoah" + EOT + "SHUT IT DOWN THE GOYIM KNOW" + EOT + "dissenter is banned" + EOT + "I'm running out of ideas, all I can do is type shitty /pol/ memes" + EOT ; //string[] multiSendDrifting = original.Split(EOT); List <byte[]> wew = new List <byte[]>(); int stringpos = 0; SRNG rand = new SRNG(); while (stringpos < original.Length) { int next = stringpos + rand.NextInt(2, 47); if (next > original.Length) { next = original.Length; } int diff = next - stringpos; string cut = original.Substring(stringpos, diff); stringpos = next; Debug.Log("Cut " + cut, "cyan"); wew.Add(cut.ToBytesUTF8()); } byte[][] multibytarraydrifting = wew.ToArray(); EncDec encDec = new EncDec(); StringBuilder held = ""; string str; int pos = 0; Debug.Log("Faking sending bullshit", "purp"); foreach (var bytes in multibytarraydrifting) { byte[] message = encDec.Encrypt(bytes); Debug.Log("Encrypting " + message.Length + " bytes"); message = encDec.Decrypt(message); str = message.GetStringUTF8(); Debug.Log("Sent [" + str.Replace("" + EOT, "<EOT>") + "]", "yellow"); held += str; int index = held.IndexOf(EOT); while (index >= 0) { string pulled = held.Substring(0, index); held = held.Remove(0, index + 1); index = held.IndexOf(EOT); if (pulled.Length > 0) { Debug.Log("Pulled message " + pos + ": " + pulled, "ltorange"); } //TBD: Pass the message to a location for it to be handled, something like the following line //Server.main.messages.Enqueue(new Message(this, pulled)); } pos++; } //*/ }