Created
April 18, 2020 09:05
-
-
Save numberoverzero/910f8abd90cb2f0a3eba576932576416 to your computer and use it in GitHub Desktop.
utility functions for filename nonces
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
byte[] Sha256(string s) | |
{ | |
using (var hash = SHA256.Create()) | |
{ | |
return hash.ComputeHash(Encoding.UTF8.GetBytes(s)); | |
} | |
} | |
byte[] Fold(byte[] input) | |
{ | |
if (input.Length == 0) return new byte[0]; | |
if (input.Length % 2 == 1) | |
{ | |
throw Exceptions.IllegalArgument("input", "an even length"); | |
} | |
int length = input.Length / 2; | |
byte[] output = new byte[length]; | |
for (int i=0; i<length; i++) | |
{ | |
output[i] = (byte)(input[i] ^ input[i + length]); | |
} | |
return output; | |
} | |
string Base64Encode(byte[] b) | |
{ | |
return System.Convert.ToBase64String(b); | |
} |
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
void usage() { | |
var hash = Sha256("hello"); | |
var shortened = Fold(hash); | |
var encoded = Base64Encode(shortened); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment