using System.Collections.Generic;
public static bool IsHex(IEnumerable<char> chars)
isHex = ((c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'f') ||
public static void Main()
string inStrGUID = "{12345678-ABCD-EFAB-1234-ABCDEFABCDEF}";
string expectedCompressedGUID = "87654321DCBABAFE2143BADCFEBADCFE";
string outputFormat = "N";
string outCompressedGuid = "";
string outDecompressedGuid = "";
Guid inGuid = new Guid();
Guid outGuid = new Guid();
Guid outDCGuid = new Guid();
bool isValidGuid = Guid.TryParse(inStrGUID, out inGuid);
Console.WriteLine("Input GUID " + inStrGUID+ " is valid? "+isValidGuid);
string raw = inGuid.ToString("N");
char[] aRaw = raw.ToCharArray();
= new int[]{8, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2};
for (int i = 0; i < revs.Length; i++)
Array.Reverse(aRaw, pos, revs[i]);
string newstrGuid = new string(aRaw);
bool isoutValidGuid = Guid.TryParse(newstrGuid, out outGuid);
outCompressedGuid = outGuid.ToString(outputFormat).ToUpper();
Console.WriteLine("out CGUID "+ outGuid.ToString("B").ToUpper()+" before full compression (removal of dashes) here for readability");
Console.WriteLine("\nCompressed guid is "+ outCompressedGuid );
if (outCompressedGuid == expectedCompressedGUID)
Console.WriteLine("Matched expectations.");
Console.WriteLine("Did not met expectations.");
Console.WriteLine("Failed to compress GUID.");
Console.WriteLine("\nInput Compressed GUID " + outCompressedGuid);
char[] chrArrCGUID = outCompressedGuid.ToCharArray();
if (outCompressedGuid.Length == 32 && Program.IsHex(chrArrCGUID)==true){
int[] reversalidxs= new int[]{8, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2};
for (int i = 0; i < reversalidxs.Length; i++)
Array.Reverse(chrArrCGUID, pos, reversalidxs[i]);
string newstrGuid = new string(chrArrCGUID);
bool isoutValidDCGuid = Guid.TryParse(newstrGuid, out outDCGuid );
if ( isoutValidDCGuid ) {
outDecompressedGuid = outDCGuid.ToString("B").ToUpper();
Console.WriteLine("Output Decomprsd GUID "+ outDCGuid.ToString("N").ToUpper()+" this line for comparison only");
Console.WriteLine("\nDecompressed compressed guid is "+ outDecompressedGuid );
Console.WriteLine("Failed to decompressed CGUID.");