Skip to content

Instantly share code, notes, and snippets.

@sholfen
Created July 22, 2018 15:06
Show Gist options
  • Save sholfen/1fd33250811e46e1e03d224384162967 to your computer and use it in GitHub Desktop.
Save sholfen/1fd33250811e46e1e03d224384162967 to your computer and use it in GitHub Desktop.
create short string from long string
public static class UtilityFunction
{
public static string GetUniqueId(string input)
{
string result = string.Empty;
char[] chars = new char[]
{
'a','b','c','d','e','f','g','h',
'i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x',
'y','z','0','1','2','3','4','5',
'6','7','8','9','A','B','C','D',
'E','F','G','H','I','J','K','L',
'M','N','O','P','Q','R','S','T',
'U','V','W','X','Y','Z'
};
byte[] bytes = Encoding.UTF8.GetBytes(input);
MD5 md5 = MD5.Create();
byte[] md5Bytes = md5.ComputeHash(bytes);
string strMd5Result = BitConverter.ToString(md5Bytes).Replace("-", string.Empty);
for (int i = 0; i < 1; i++)
{
int intMd5SubStr = Convert.ToInt32(strMd5Result.Substring(i * 8, 8), 16);
Console.WriteLine(intMd5SubStr);
for (int j = 0; j < 6; j++)
{
int intMask = 31; //0x001F
result += chars[intMask & intMd5SubStr];
intMd5SubStr >>= 5;
}
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment