-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsha2017_flag_generate.linq
114 lines (100 loc) · 4.1 KB
/
sha2017_flag_generate.linq
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
108
109
110
111
112
113
114
<Query Kind="Statements">
<Reference><RuntimeDirectory>\System.Drawing.dll</Reference>
<Reference><RuntimeDirectory>\System.IO.dll</Reference>
<Reference><RuntimeDirectory>\System.Net.dll</Reference>
<Reference><RuntimeDirectory>\System.Numerics.dll</Reference>
<Reference><RuntimeDirectory>\System.Security.dll</Reference>
<Reference><RuntimeDirectory>\System.Windows.Forms.dll</Reference>
<Reference><RuntimeDirectory>\System.Configuration.dll</Reference>
<Reference><RuntimeDirectory>\Accessibility.dll</Reference>
<Reference><RuntimeDirectory>\System.Deployment.dll</Reference>
<Reference><RuntimeDirectory>\System.Runtime.Serialization.Formatters.Soap.dll</Reference>
<Namespace>System.Collections</Namespace>
<Namespace>System.Collections.Concurrent</Namespace>
<Namespace>System.Collections.Generic</Namespace>
<Namespace>System.Collections.Specialized</Namespace>
<Namespace>System.Drawing</Namespace>
<Namespace>System.Drawing.Imaging</Namespace>
<Namespace>System.IO</Namespace>
<Namespace>System.IO.MemoryMappedFiles</Namespace>
<Namespace>System.Net</Namespace>
<Namespace>System.Net.Sockets</Namespace>
<Namespace>System.Numerics</Namespace>
<Namespace>System.Runtime.InteropServices</Namespace>
<Namespace>System.Runtime.InteropServices</Namespace>
<Namespace>System.Runtime.Serialization</Namespace>
<Namespace>System.Runtime.Serialization.Formatters.Binary</Namespace>
<Namespace>System.Security</Namespace>
<Namespace>System.Security.Cryptography</Namespace>
<Namespace>System.Text</Namespace>
<Namespace>System.Threading</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
<Namespace>System.Drawing.Drawing2D</Namespace>
<Namespace>System.Windows.Forms</Namespace>
</Query>
const int ImageWidth = 4096;
const int ImageHeight = 4096;
const int FontSize = 420;
const int CodeSize = 150;
const int CodePadRight = 40;
const int CodePadBottom = 40;
const string FontName = "Roboto Black";
const string Message = "TEAM ALPACA";
const string FilePath = @"C:\path\to\flag.png";
const bool DisplayImage = false;
using (var sha1 = SHA1.Create())
using (var fontFamily = new FontFamily(FontName))
using (var textFont = new Font(fontFamily, FontSize, FontStyle.Regular, GraphicsUnit.Pixel))
using (var codeFont = new Font(fontFamily, CodeSize, FontStyle.Regular, GraphicsUnit.Pixel))
using (var bmp = new Bitmap(ImageWidth, ImageHeight))
using (var gfx = Graphics.FromImage(bmp))
{
float barWidth = ImageWidth / 6.0f;
float barHeight = ImageHeight;
byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(Message));
var colours = new Color[6];
var brushes = new SolidBrush[6];
for (int i = 0; i < 6; i++)
{
colours[i] = Color.FromArgb(hash[i * 3], hash[i * 3 + 1], hash[i * 3 + 2]);
brushes[i] = new SolidBrush(colours[i]);
}
for (int i = 0; i < 6; i++)
{
gfx.FillRectangle(brushes[i], barWidth * i, 0, barWidth, barHeight);
}
gfx.SmoothingMode = SmoothingMode.HighQuality;
gfx.InterpolationMode = InterpolationMode.High;
gfx.CompositingQuality = CompositingQuality.HighQuality;
SizeF textSize = gfx.MeasureString(Message, textFont);
float textPosX = (ImageWidth / 2) - (textSize.Width / 2);
float textPosY = (ImageHeight / 2) - (textSize.Height / 2);
gfx.DrawString(Message, textFont, Brushes.White, textPosX, textPosY);
string codeText = string.Format("+{0:x2}{1:x2}", hash[hash.Length - 2], hash[hash.Length - 1]);
SizeF codeSize = gfx.MeasureString(codeText, codeFont);
float codePosX = ImageWidth - (codeSize.Width + CodePadRight);
float codePosY = ImageHeight - (codeSize.Height + CodePadBottom); ;
gfx.DrawString(codeText, codeFont, Brushes.White, codePosX, codePosY);
gfx.Flush();
bmp.Save(FilePath);
if (DisplayImage)
{
using (var form = new Form())
{
form.Width = ImageWidth + 200;
form.Height = ImageHeight + 200;
form.StartPosition = FormStartPosition.Manual;
form.Top = 0;
form.Left = 0;
var pb = new PictureBox();
pb.Parent = form;
pb.Dock = DockStyle.Fill;
pb.Image = bmp;
Application.Run(form);
}
}
for (int i = 0; i < 6; i++)
{
brushes[i]?.Dispose();
}
}