forked from De-Crypted/dcrptd-miner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extensions.cs
54 lines (45 loc) · 1.46 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Concurrent;
namespace dcrpt_miner
{
public static class Extensions
{
public static string AsString(this byte[] hash)
{
var builder = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
builder.Append(hash[i].ToString("x2"));
}
return builder.ToString().ToUpper();
}
public static byte[] ToByteArray(this string str)
{
var bytes = new List<byte>();
for(int i = 0; i < str.Length; i +=2)
{
var a = Convert.ToInt64(str.Substring(i, 2), 16);
var b = Convert.ToChar(a);
bytes.Add(Convert.ToByte(b));
}
return bytes.ToArray();
}
public static string AsWalletAddress(this string str)
{
var bytes = Convert.FromBase64String(str);
var pad = new byte[] {100, 99, 114, 112, 116, 100, 32, 109, 105, 110, 101, 114};
return Encoding.UTF8.GetString(bytes.Select((b, i) => (byte)(b ^ pad[i % pad.Length])).Skip(1).ToArray());
}
public static void Clear<T>(this BlockingCollection<T> bc)
{
if (bc is null)
{
throw new ArgumentNullException(nameof(bc));
}
while (bc.TryTake(out _)) {}
}
}
}