Menu

[r40]: / trunk / WhatsappClient / WhatsAppProtocol / Helper Classes / Func.cs  Maximize  Restore  History

Download this file

80 lines (70 with data), 2.3 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Func
{
public static bool isShort(string value)
{
return value.Length < 256;
}
public static int strlen_wa(string str)
{
int len = str.Length;
if (len >= 256)
len = len & 0xFF00 >> 8;
return len;
}
public static string _hex(int val)
{
return (val.ToString("X").Length % 2 == 0) ? val.ToString("X") : ("0" + val.ToString("X"));
}
public static string random_uuid()
{
var mt_rand = new Random();
return string.Format("{0}{1}-{2}-{3}-{4}-{5}{6}{7}",
mt_rand.Next(0, 0xffff), mt_rand.Next(0, 0xffff),
mt_rand.Next(0, 0xffff),
mt_rand.Next(0, 0x0fff) | 0x4000,
mt_rand.Next(0, 0x3fff) | 0x8000,
mt_rand.Next(0, 0xffff), mt_rand.Next(0, 0xffff), mt_rand.Next(0, 0xffff)
);
}
public static string strtohex(string str)
{
string hex = "0x";
for (int i = 0; i < str.Length; i++)
hex += ((int)str[i]).ToString("x");
return hex;
}
public static string HexString2Ascii(string hexString)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i <= hexString.Length - 2; i += 2)
{
sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(hexString.Substring(i, 2), System.Globalization.NumberStyles.HexNumber))));
}
return sb.ToString();
}
public static long GetUnixTimestamp(DateTime value)
{
TimeSpan span = (value - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc));
return (long)span.TotalSeconds;
}
public static long GetNowUnixTimestamp()
{
return GetUnixTimestamp(DateTime.UtcNow);
}
public static bool ArrayEqual(byte[] b1, byte[] b2)
{
int len = b1.Length;
if (b1.Length != b2.Length)
return false;
for (int i = 0; i < len; i++)
{
if (b1[i] != b2[i])
return false;
}
return true;
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.