-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigestStringBuilder.cs
More file actions
82 lines (66 loc) · 2.04 KB
/
DigestStringBuilder.cs
File metadata and controls
82 lines (66 loc) · 2.04 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Text;
namespace tlsh.digests
{
internal class DigestStringBuilder
{
private readonly StringBuilder _value;
public DigestStringBuilder()
{
_value = new StringBuilder();
}
public DigestStringBuilder Append(Checksum checksum)
{
int[] swappedChecksum = new int[checksum.GetValue().Length];
for (int k = 0; k < swappedChecksum.Length; k++)
{
swappedChecksum[k] = swap(checksum.GetValue()[k]);
}
_value.Append(ToHex(swappedChecksum));
return this;
}
public DigestStringBuilder Append(LValue lValue)
{
_value.Append(ToHex(swap(lValue.GetValue())));
return this;
}
public DigestStringBuilder Append(Q q)
{
_value.Append(ToHex(swap(q.GetValue())));
return this;
}
public DigestStringBuilder Append(Body body)
{
int[] swappedBody = new int[body.GetBody().Length];
for (int i = 0; i < swappedBody.Length; i++)
{
swappedBody[i] = body.GetBody()[swappedBody.Length - 1 - i];
}
_value.Append(ToHex(swappedBody));
return this;
}
public string Build()
{
return _value.ToString();
}
private string ToHex(int val)
{
int num = (0xFF & val);
return num.ToString("X2");
//return string.Format("%02X", (0xFF & val));
}
private string ToHex(int[] values)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < values.Length; i++)
{
result.Append(ToHex(values[i]));
}
return result.ToString().ToUpper();
}
private int swap(int data)
{
return ByteSwapper.Swap(data);
}
}
}