Last active
September 4, 2019 01:15
-
-
Save AndrewSav/4363d01238213a66f3a7c8f5e8ec8a42 to your computer and use it in GitHub Desktop.
Revisions
-
AndrewSav revised this gist
Sep 4, 2019 . No changes.There are no files selected for viewing
-
AndrewSav revised this gist
Sep 4, 2019 . No changes.There are no files selected for viewing
-
AndrewSav created this gist
Jul 28, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ string GetSteamGuardCode(string base64SharedSecret) { long time = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds + 10; byte[] timeHash = BitConverter.GetBytes(time/30).Reverse().ToArray(); HMACSHA1 hmac = new HMACSHA1(Convert.FromBase64String(base64SharedSecret)); hmac.Initialize(); byte[] hash = hmac.ComputeHash(timeHash); int b = hash[19] & 0xF; int codePoint = (hash[b] & 0x7F) << 24 | (hash[b + 1] & 0xFF) << 16 | (hash[b + 2] & 0xFF) << 8 | (hash[b + 3] & 0xFF); string steamChars = "23456789BCDFGHJKMNPQRTVWXY"; return new string(Enumerable.Range(0,5).Select(x => steamChars[codePoint/((int)Math.Pow(steamChars.Length,x)) % steamChars.Length]).ToArray()); }