Home Forums TrueRNG Hardware random number generator Verify my raw binary mode conversion?

This topic contains 0 replies, has 1 voice, and was last updated by  Kal_Torak 5 years, 4 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #2223

    Kal_Torak
    Member

    (The forum seems to bork when editing a post, reposting)

    I just picked up a TrueRNGPro after seeing that an unwhitened, uncombined mode had been added, something I’d asked about a couple years ago.

    I scribbled some C# code to parse the raw binary format into a binary string, and I was wondering if someone could do a quick cross check on my results.

    Input:
    "124,9,88,136,208,6,124,136,198,8,64,133,243,8,120,136,238,7,76,134,195,8,76,135,245,7,76,135,223,7,98,135,201,8,100,135,253,7,78,135"
    Results:
    Generator1: 100101100001101111001000000000100011100001110011001000001100011100110001111000101000100100
    Generator2: 100001000010000001100101110011100010111001100000110111110101011101111101110010010111111101
    

    The C# code if anyone is interested:

    
    var bytestr = "124,9,88,136,208,6,124,136,198,8,64,133,243,8,120,136,238,7,76,134,195,8,76,135,245,7,76,135,223,7,98,135,201,8,100,135,253,7,78,135";
    var bytes = bytestr.Split(',').Select(Byte.Parse).ToList();
    while (bytes[0] > 63)
        bytes.RemoveAt(0);
    
    var gen1Bits = new BitArray(90);
    var gen2Bits = new BitArray(90);
    var cursor = 0;
    while (bytes.Count >= 4)
    {
        var sample = bytes.TakeWhile((b, idx) => (b & idx << 6) == idx << 6).ToArray();
        //grab high order idx 3-0
        for (int i = 4; i > 0; i--)
        {
            gen1Bits.Set(cursor, (sample[0] & (1 << i - 1)) != 0);
            gen2Bits.Set(cursor, (sample[2] & (1 << i - 1)) != 0);
            cursor++;
        }
        //grab low order idx 5-0
        for (int i = 6; i > 0; i--)
        {
            gen1Bits.Set(cursor, (sample[1] & (1 << i - 1)) != 0);
            gen2Bits.Set(cursor, (sample[3] & (1 << i - 1)) != 0);
            cursor++;
        }
        bytes.RemoveRange(0, 4);
    }
    Console.WriteLine(gen1Bits.Cast<bool>().Aggregate("", (memo, bit) => memo + (bit ? 1 : 0)));
    Console.WriteLine(gen2Bits.Cast<bool>().Aggregate("", (memo, bit) => memo + (bit ? 1 : 0)));
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.