orilon

C# Shorten String

Jun 4th, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Thanks to the guest who posted this - but we can do without the swearing ( )o( )...
  2.  
  3. private static Random rnd = new Random();
  4. private static string Shorten(string input)
  5. {
  6.     char[] arr = "ABCDEFGHIJKLMNOPQRSTUVWXQY123456789!@#$%^&*()".ToCharArray();
  7.     for (int i = 0; i < 5; i++)
  8.         input += arr[rnd.Next(0, arr.Length)];
  9.     MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
  10.     byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
  11.     bs = x.ComputeHash(bs);
  12.     System.Text.StringBuilder s = new System.Text.StringBuilder();
  13.     foreach (byte b in bs)
  14.         s.Append(b.ToString("x2").ToLower());
  15.     return s.ToString().Remove(s.Length / + 5);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment