1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public: char ConvOctHexAscii(unsigned char OctHex)
{
if (OctHex < 0x0a)
OctHex = (OctHex + 0x30);
else
OctHex = (OctHex + 0x37);
return (OctHex);
}
private: String^ GetRandomHexNumber(int digits)
{
Random^ random = gcnew Random();
array< unsigned char>^ buffer = gcnew array <unsigned char>(digits / 2);
random->NextBytes(buffer);
array< unsigned char>^ buffer1 = gcnew array <unsigned char>(digits+1);
for (char i = 0, j=0;j < digits/2;i++,j++)
{
buffer1[i] = ConvOctHexAscii(buffer[j] >> 4);
i++;
buffer1[i] = ConvOctHexAscii(buffer[j] & 0x0f);
}
buffer1[digits] = 0;
String^ str = System::Text::Encoding::Default->GetString(buffer1);
return str;
} |