BplusDotNet.hBplusTreeBytes.PrefixForByteCount C# (CSharp) Method

PrefixForByteCount() public method

public PrefixForByteCount ( string s, int maxbytecount ) : string
s string
maxbytecount int
return string
        public override string PrefixForByteCount(string s, int maxbytecount)
        {
            byte[] inputbytes = BplusTree.StringToBytes(s);
            System.Security.Cryptography.MD5 D = System.Security.Cryptography.MD5.Create();
            byte[] digest = D.ComputeHash(inputbytes);
            byte[] resultbytes = new byte[maxbytecount];
            // copy digest translating to printable ascii
            for (int i=0; i<maxbytecount; i++)
            {
                int r = digest[i % digest.Length];
                if (r>127)
                {
                    r = 256-r;
                }
                if (r<0)
                {
                    r = -r;
                }
                //Console.WriteLine(" before "+i+" "+r);
                r = r%79 + 40; // printable ascii
                //Console.WriteLine(" "+i+" "+r);
                resultbytes[i] = (byte)r;
            }
            string result = BplusTree.BytesToString(resultbytes);
            return result;
        }