Last active
December 7, 2023 17:58
-
-
Save benharri/3afecb9900a37220a3281d5aad93657c to your computer and use it in GitHub Desktop.
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 characters
<Query Kind="Program"> | |
<Namespace>System.Security.Cryptography</Namespace> | |
<Namespace>LINQPad.Controls</Namespace> | |
<AutoDumpHeading>true</AutoDumpHeading> | |
</Query> | |
DumpContainer results = new(); | |
DumpContainer notice = new(); | |
DumpContainer byteCount = new(); | |
StringBuilder sb = new(); | |
List<string> rarities = [ | |
"common", | |
"uncommon", | |
"rare", | |
"epic", | |
"legendary", | |
"mythic", | |
"???" | |
]; | |
void Main() | |
{ | |
"Type your poem here".Dump(); | |
Update(new TextArea("DON'T WORRY", 64, Update).Dump()); | |
results.Dump(); | |
byteCount.Dump(); | |
notice.Dump(); | |
void Update(TextArea area) | |
{ | |
var bytes = Encoding.UTF8.GetBytes(area.Text.Replace("\r", "")); | |
var hashBytes = SHA256.HashData(bytes); | |
sb.Clear(); | |
for (var i = 0; i < hashBytes.Length; i++) | |
sb.Append(hashBytes[i].ToString("x2")); | |
var hash = sb.ToString(); | |
results.Content = hash; | |
var eights = Regex.Matches(hash, "8{4,}"); | |
if (bytes.Length > 64) | |
notice.Content = $"Too long to be an amulet"; | |
else if (eights.Count >= 1) | |
{ | |
var rarity = eights.First().Length - 4; | |
notice.Content = $"You found an amulet of {rarities[rarity]} rarity!"; | |
} | |
else notice.Content = ""; | |
byteCount.Content = $"{bytes.Length} byte poem"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment