T
Tech Aspirant
Guest
Hello,
Please help me I want to convert below C# class to C code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ZenSetGroupPolicy
{
public class SNGenerator
{
public enum
SNKeyLength
{
SN16 = 16, SN20 = 20, SN24 = 24, SN28 = 28, SN32 = 32
}
public enum SNKeyNumLength
{
SN4 = 4, SN8 = 8, SN12 =
12
}
public static class RandomSNKGenerator
{
private static string
AppendSpecifiedStr(int length, string str, char[] newKey)
{
string
newKeyStr = "";
int k = 0;
for (int i = 0; i < length; i++)
{
for
(k = i; k < 4 + i; k++)
{
newKeyStr += newKey[k];
}
if (k ==
length)
{
break;
}
else
{
i = (k) - 1;
newKeyStr +=
str;
}
}
return newKeyStr;
}
///
/// Generate
//standard serial key with alphanumaric format
///
///
//the supported length of the serial
// key
/// returns formated serial
//key
public static string GetSerialKeyAlphaNumaric(SNKeyLength
keyLength, string input)
{
string newSerialNumber = "";
using (MD5 md5 = MD5.Create())
{
byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(input));
Guid newguid = new Guid(hash);
string randomStr =
newguid.ToString("N");
string tracStr = randomStr.Substring(0,
(int)keyLength);
tracStr = tracStr.ToUpper();
char[] newKey =
tracStr.ToCharArray();
switch (keyLength
)
{
case SNKeyLength.SN16:
newSerialNumber = AppendSpecifiedStr(16,
"-", newKey);
break;
case SNKeyLength.SN20:
newSerialNumber =
AppendSpecifiedStr(20, "-", newKey);
break;
case
SNKeyLength.SN24:
newSerialNumber = AppendSpecifiedStr(24, "-",
newKey);
break;
case SNKeyLength.SN28:
newSerialNumber =
AppendSpecifiedStr(28, "-", newKey);
break;
case
SNKeyLength.SN32:
newSerialNumber = AppendSpecifiedStr(32, "-",
newKey);
break;
}
}
return newSerialNumber;
}
///
/// Generate serial key with only numaric
///
/// the supported length of
//the serial key
/// returns formated serial
//key
public static string GetSerialKeyNumaric(SNKeyNumLength
keyLength)
{
Random rn = new Random();
double sd =
Math.Round(rn.NextDouble() * Math.Pow(10, (int)keyLength) + 4);
return
sd.ToString().Substring(0, (int)keyLength);
}
}
public static void GrantAccess()
{
}
}
}
Input : SNGenerator.RandomSNKGenerator.GetSerialKeyAlphaNumaric(SNGenerator.SNKeyLength.SN20, "Hello World");
Output : B18D-0AB1-E064-4175-05B7
Continue reading...
Please help me I want to convert below C# class to C code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ZenSetGroupPolicy
{
public class SNGenerator
{
public enum
SNKeyLength
{
SN16 = 16, SN20 = 20, SN24 = 24, SN28 = 28, SN32 = 32
}
public enum SNKeyNumLength
{
SN4 = 4, SN8 = 8, SN12 =
12
}
public static class RandomSNKGenerator
{
private static string
AppendSpecifiedStr(int length, string str, char[] newKey)
{
string
newKeyStr = "";
int k = 0;
for (int i = 0; i < length; i++)
{
for
(k = i; k < 4 + i; k++)
{
newKeyStr += newKey[k];
}
if (k ==
length)
{
break;
}
else
{
i = (k) - 1;
newKeyStr +=
str;
}
}
return newKeyStr;
}
///
/// Generate
//standard serial key with alphanumaric format
///
///
//the supported length of the serial
// key
/// returns formated serial
//key
public static string GetSerialKeyAlphaNumaric(SNKeyLength
keyLength, string input)
{
string newSerialNumber = "";
using (MD5 md5 = MD5.Create())
{
byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(input));
Guid newguid = new Guid(hash);
string randomStr =
newguid.ToString("N");
string tracStr = randomStr.Substring(0,
(int)keyLength);
tracStr = tracStr.ToUpper();
char[] newKey =
tracStr.ToCharArray();
switch (keyLength
)
{
case SNKeyLength.SN16:
newSerialNumber = AppendSpecifiedStr(16,
"-", newKey);
break;
case SNKeyLength.SN20:
newSerialNumber =
AppendSpecifiedStr(20, "-", newKey);
break;
case
SNKeyLength.SN24:
newSerialNumber = AppendSpecifiedStr(24, "-",
newKey);
break;
case SNKeyLength.SN28:
newSerialNumber =
AppendSpecifiedStr(28, "-", newKey);
break;
case
SNKeyLength.SN32:
newSerialNumber = AppendSpecifiedStr(32, "-",
newKey);
break;
}
}
return newSerialNumber;
}
///
/// Generate serial key with only numaric
///
/// the supported length of
//the serial key
/// returns formated serial
//key
public static string GetSerialKeyNumaric(SNKeyNumLength
keyLength)
{
Random rn = new Random();
double sd =
Math.Round(rn.NextDouble() * Math.Pow(10, (int)keyLength) + 4);
return
sd.ToString().Substring(0, (int)keyLength);
}
}
public static void GrantAccess()
{
}
}
}
Input : SNGenerator.RandomSNKGenerator.GetSerialKeyAlphaNumaric(SNGenerator.SNKeyLength.SN20, "Hello World");
Output : B18D-0AB1-E064-4175-05B7
Continue reading...