-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVLR_Dio_Puzzle.m
More file actions
295 lines (247 loc) · 9.23 KB
/
VLR_Dio_Puzzle.m
File metadata and controls
295 lines (247 loc) · 9.23 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
function [] = VLR_Dio_Puzzle()
S.count=0;
S.fh = figure('units','pixels',... %This describes the overall figure dimensions
'position',[200 140 800 500],...
'menubar','none',...
'name','VLR Dio Puzzle',...
'Resize','off',...
'NumberTitle','off');
movegui('center')
S.GameRules = uicontrol('style','text',...
'unit','pix',...
'FontSize',10,...
'Position',[660 200 120 230],...
'string',{'Rules:';'';'P.1: Enter message and numeric key';' ';'P.2: Guess message from key. You have 5 tries.';' '; 'Note: sometimes an extra space shows up in P1 message beginning. Remove it.'},...
'HorizontalAlignment','left');
S.Player1Panel = uipanel('Title','Player l',...
'unit','pix',...
'FontSize',12,...
'Position',[40 310 590 180]);
S.P1Frame = uicontrol('style','frame',...
'BackgroundColor','white',...
'unit','pix',...
'position',[460 370 90 90]);
S.EnterMessage = uicontrol('style','text',...
'unit','pix',...
'position',[80 440 140 20],...
'min',0,'max',2,...
'fontsize',10,...
'HorizontalAlignment','left',...
'string',{'Enter Message'});
S.MessageText = uicontrol('style','edit',...
'unit','pix',...
'position',[80 410 250 20],...
'min',0,'max',1,...
'BackgroundColor','white',...
'fontsize',10,...
'HorizontalAlignment','left',...
'CallBack',@callb,...
'string','');
S.EnterNumericKey = uicontrol('style','text',...
'unit','pix',...
'position',[80 370 140 20],...
'min',0,'max',2,...
'fontsize',10,...
'HorizontalAlignment','left',...
'string',{'Enter Numeric Key'});
S.KeyText = uicontrol('style','edit',...
'unit','pix',...
'position',[80 340 250 20],...
'min',0,'max',1,...
'fontsize',10,...
'BackgroundColor','white',...
'HorizontalAlignment','left',...
'CallBack',@callb,...
'string','');
S.Encrypt = uicontrol('style','pushbutton',...
'unit','pix',...
'position',[440 340 130 20],...
'min',0,'max',1,...
'fontsize',10,...
'CallBack',@ENCRYPT,...
'string',{'Encrypt'});
S.Player2Panel = uipanel('Title','Player 2',...
'unit','pix',...
'FontSize',12,...
'Position',[40 20 590 280]);
S.P2Frame = uicontrol('style','frame',...
'BackgroundColor','white',...
'unit','pix',...
'position',[460 180 90 90]);
S.EncryptedMessage = uicontrol('style','text',...
'unit','pix',...
'position',[80 250 140 20],...
'fontsize',10,...
'HorizontalAlignment','left',...
'CallBack',@callb,...
'string',{'Encrypted Message'});
S.FrameEncryption = uicontrol('style','frame',...
'BackgroundColor','white',...
'unit','pix',...
'position',[78 28 304 204],...
'min',0,'max',16,...
'fontsize',10,...
'string',{''});
S.Encryption = uicontrol('style','edit',...
'BackgroundColor','white',...
'unit','pix',...
'position',[80 30 300 200],...
'min',0,'max',16,...
'fontsize',14,...
'CallBack',@ENCRYPT,...
'string',' ',...
'HorizontalAlignment','left');
S.GuessTheMessage = uicontrol('style','text',...
'unit','pix',...
'position',[445 110 120 20],...
'fontsize',10,...
'string',{'Guess the Message'});
S.GuessText = uicontrol('style','edit',...
'BackgroundColor','white',...
'unit','pix',...
'position',[400 80 220 20],...
'fontsize',10,...
'HorizontalAlignment','left',...
'CallBack',@callb,...
'string','');
S.Reset = uicontrol('style','pushbutton',...
'unit','pix',...
'FontSize',10,...
'Position',[660 50 120 20],...
'string',{'Reset'});
S.Close = uicontrol('style','pushbutton',...
'unit','pix',...
'FontSize',10,...
'Position',[660 20 120 20],...
'CallBack',@CLOSE,...
'string',{'Close'});
S.Guess = uicontrol('style','pushbutton',...
'unit','pix',...
'position',[445 50 120 20],...
'min',0,'max',1,...
'fontsize',10,...
'string',{'Guess'});
S.GuessStatic = uicontrol('style','text',...
'unit','pix',...
'position',[660 150 120 20],...
'min',0,'max',1,...
'fontsize',10,...
'string',{'Current Guess'});
S.GuessNo = uicontrol('style','edit',...
'BackgroundColor','white',...
'unit','pix',...
'position',[710 125 15 20],...
'fontsize',10,...
'HorizontalAlignment','center',...
'CallBack',@callb,...
'string','1');
set(S.Guess,'CallBack',{@GUESS,S});
set(S.Reset,'CallBack',{@RESET,S});
guidata(S.fh,S); %Stores the S values
end
function [] = callb(varargin)
S = guidata(gcbf);
end
function [] = ENCRYPT(varargin)
S = guidata(gcbf);
uicontrol(S.GuessText);
set(S.MessageText,'BackgroundColor','black');
S.P1 = upper(get(S.MessageText,'string'));
S.KT = sscanf(get(S.KeyText,'string'),'%1d',inf).';
if length(S.KT) > 16 %Makes sure Key length is not larger than 16
S.P1 = 'Make the key less than 16 digits. Hit Reset.';
set(S.Encryption,'string',S.P1)
error('Use less than 16 digits.')
end
for i=1:1:length(S.KT) %Makes sure some dumbass doesn't type in 0
if S.KT(i)==0
S.P1 = 'My God! Are you fucking retarded!?';
set(S.Encryption,'string',S.P1)
error ('Do not type in 0, or any non-number!')
end
end
while length(S.KT)<length(S.P1) %Doubles length of Key in case it is smaller than message
S.KT = [S.KT,S.KT];
end
while length(S.KT)>length(S.P1) %Removes elements at length points longer than message
S.KT(length(S.P1)+1)=[];
end
Encryption = zeros(1,sum(S.KT)); %Primes Encryption Array
for k =1:1:length(S.KT)
if k ==1
summer = S.KT(k);
else
summer = summer + S.KT(k);
end
Encryption(summer) = (S.P1(k)); %Ensures message is set into correct key placement locations of Encryption
end
for k =1:1:length(Encryption)
if Encryption(k) == 0
Encryption(k) = char(randi([65,90])); %Array elements that do not have message are randomized
end
end
for i =1:1:length(Encryption)
j = i + (i-1);
EncryptionWithSpaces(j)= Encryption(i);
if i > 1
EncryptionWithSpaces(j-1) = 1; %Puts spaces between letters for easier reading
end
end
counter=1;
while ~isempty(EncryptionWithSpaces)
if length(EncryptionWithSpaces) <= 19
for j=1:1:length(EncryptionWithSpaces)
EF(counter,j)=EncryptionWithSpaces(j);
end
EncryptionWithSpaces(1:length(EncryptionWithSpaces))=[];
else
for j=1:1:19
EF(counter,j) = EncryptionWithSpaces(j);
end
EncryptionWithSpaces(1:20)=[];
end
counter=counter+1;
end
EF = char(EF);
set(S.Encryption,'string',EF);
end
function [] = GUESS(varargin)
N = numel(varargin); % 3 elements in "varagin": the 3rd is where the S data is
S = varargin{N}; %extracts S data
S.count = S.count+1;
if S.count >= 5
set(S.P1Frame,'BackgroundColor','green');
set(S.P2Frame,'BackgroundColor','red');
set(S.MessageText,'BackgroundColor','white');
end
set(S.Guess,'CallBack',{@GUESS,S});
S.GT = upper(get(S.GuessText,'string'));
S.P1 = upper(get(S.MessageText,'string'));
if (strcmp(S.GT,S.P1))==1 %Checks if strings equal eachother
set(S.P1Frame,'BackgroundColor','red');
set(S.P2Frame,'BackgroundColor','green');
set(S.MessageText,'BackgroundColor','white');
else
if S.count ~= 5
set(S.GuessNo,'string',S.count+1);
else
set(S.GuessNo,'string','F');
end
end
end
function [] = RESET(varargin)
N=numel(varargin);
S = varargin{N};
set(S.MessageText,'string',' ','BackgroundColor','white');
set(S.KeyText,'string',' ');
set(S.Encryption,'string',' ');
set(S.GuessText,'string',' ');
set(S.P1Frame,'BackgroundColor','white');
set(S.P2Frame,'BackgroundColor','white');
set(S.GuessNo,'string','1');
S.count=0;
set(S.Guess,'CallBack',{@GUESS,S});
end
function [] = CLOSE(varargin)
close all
end