-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
107 lines (85 loc) · 2.84 KB
/
Program.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OpenPGPExplorer
{
static class Program
{
public static readonly int MAX_PACKET_LENGTH = 10000000;
public static readonly int MAX_ARMORED_LENGTH = 10000000;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMain());
TempFiles.Clear();
}
public static long GetCRC24(byte[] octets)
{
long crc = 0xB704CEL;
int len = octets.Length;
int i;
while (len-- > 0)
{
crc ^= octets[octets.Length - len - 1] << 16;
for (i = 0; i < 8; i++)
{
crc <<= 1;
if ((crc & 0x1000000) != 0)
crc ^= 0x1864CFBL;
}
}
return crc & 0xFFFFFFL;
}
public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
{
// Unix timestamp is seconds past epoch
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
return dtDateTime;
}
public static int GetBlockAlignRemainder(int DataSize, int BlockSize)
{
if (DataSize % BlockSize == 0)
return 0;
return BlockSize - (DataSize % BlockSize);
}
public static string ToHexString(this byte b)
{
return "0x" +b.ToString("X2");
}
public static byte[] GetMPIBytes(byte[] Buffer, ref int Idx)
{
uint LengthBits = Program.GetBigEndian(Buffer, Idx, 2);
int bytes = (int)Math.Ceiling(LengthBits / 8.0);
Idx += 2;
byte[] data = new byte[bytes];
Array.Copy(Buffer, Idx, data, 0, bytes);
Idx += bytes;
return data;
}
public static uint GetBigEndian(byte[] DataBytes, int idx, int LengthBytes)
{
uint length = 0;
for (int i = idx; i < idx + LengthBytes; i++)
{
length |= DataBytes[i];
if (i < idx + LengthBytes - 1)
length <<= 8;
}
return length;
}
public static T[] SubArray<T>(this T[] data, int index, int length)
{
T[] result = new T[length];
Array.Copy(data, index, result, 0, length);
return result;
}
}
}