Exemplo n.º 1
0
    // test seed converter for all possible seed sizes
    //  Creates a byte array filled with maximum possible values for N bits, and
    //  converts to an action list and back with seedConverterUniversal()
    public int[] testAllSizeSeeds()
    {
        int[] passed = new int[2];

        for (int i = 10; i < 129; i++)
        {
            List <int> hexList = new List <int>();
            for (int j = 0; j < i; j++)
            {
                hexList.Add(1);
            }

            byte[] byteHex = new byte[(i / 8) + 1];

            if (i % 8 == 0)
            {
                byteHex = new byte[i / 8];
            }

            for (int j = 0; j < byteHex.Length; j++)
            {
                byteHex[j] = 255;
            }

            byteHex[byteHex.Length - 1] = (byte)(Math.Pow(2, i % 8) - 1);

            BitArray hexBits    = seedToByte.byteToBits(byteHex);
            int[]    hexActions = seedToByte.bitToActions(hexBits, hexList);
            byte[]   finalSeed  = SeedToByte.seedConverterUniversal(hexActions, hexList);

            passed[1] += 1;

            if (seedToByte.byteToSeed(byteHex) == seedToByte.byteToSeed(finalSeed))
            {
                passed[0] += 1;
            }
            else
            {
                Debug.Log("Test for seed size of: " + i + " failed.");
            }
        }

        return(passed);
    }
Exemplo n.º 2
0
    public int[] testBreakPoints()
    {
        int[] passed = new int[2];

        string testHex = "FFFFAAAAFFFFAAAA";

        byte[]     testHexSeed = SeedToByte.HexStringToByteArray(testHex);
        List <int> tempList    = SeedToByte.customList(4, 8, 6, 2, 2);
        BitArray   seedBits    = seedToByte.byteToBits(testHexSeed);

        int[]  actions   = seedToByte.bitToActions(seedBits, tempList);
        byte[] finalSeed = SeedToByte.seedConverterUniversal(actions, tempList);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test for converting 64 bit seed to action list and back failed");
        }

        testHex     = "FFFFAAAAFFFFAAAAFFFFAAAAFFFFAAAA";
        testHexSeed = SeedToByte.HexStringToByteArray(testHex);
        tempList    = SeedToByte.customList(4, 8, 6, 2, 4);
        seedBits    = seedToByte.byteToBits(testHexSeed);
        actions     = seedToByte.bitToActions(seedBits, tempList);
        finalSeed   = SeedToByte.seedConverterUniversal(actions, tempList);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test for converting 128 bit seed to action list and back failed");
        }

        return(passed);
    }
Exemplo n.º 3
0
    public int[] testMultipleSizeSeeds()
    {
        int[] passed = new int[2];

        string testHex = "FFFFAAAAFFFFAAAAFFFFDDDDFFFF";

        byte[] testHexSeed = SeedToByte.HexStringToByteArray(testHex);
        byte[] testRunSeed = new byte[14];
        testRunSeed = OTPworker.randomSeedGenerator(testRunSeed);

        List <int> tempList1 = SeedToByte.customList(4, 4, 2, 4, 4);
        List <int> tempList2 = SeedToByte.customList(3, 4, 2, 4, 4);

        BitArray seedBits1 = seedToByte.byteToBits(testRunSeed);
        BitArray seedBits2 = seedToByte.byteToBits(testHexSeed);

        int[] actions1 = seedToByte.bitToActions(seedBits1, tempList1);
        int[] actions2 = seedToByte.bitToActions(seedBits2, tempList1);

        byte[] finalSeed1 = SeedToByte.seedConverterUniversal(actions1, tempList1);
        byte[] finalSeed2 = SeedToByte.seedConverterUniversal(actions2, tempList1);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testRunSeed) == seedToByte.byteToSeed(finalSeed1))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test 1 for converting 112 bit seed to action list and back failed");
        }

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed2))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test 2 for converting 112 bit seed to action list and back failed");
        }

        testHexSeed = new byte[14];
        testRunSeed = OTPworker.randomSeedGenerator(testRunSeed);

        if (testRunSeed[13] > 7)
        {
            testRunSeed[13] = (byte)((int)testRunSeed[13] % 7);
        }

        BitArray seedBits = seedToByte.byteToBits(testHexSeed);

        int[] actions3 = seedToByte.bitToActions(seedBits, tempList2);

        byte[] finalSeed3 = SeedToByte.seedConverterUniversal(actions3, tempList2);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed3))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test for converting 108 bit seed to action list and back failed");
        }

        return(passed);
    }