DIFFICULT MATLAB QUESTION The function m-file used to randomly generate the pass
ID: 3698316 • Letter: D
Question
DIFFICULT MATLAB QUESTION
The function m-file used to randomly generate the password matrix. The password matrix is a numeric matrix where each element contains an integer number (** Notice: the number is not necessarily a single digit! **). The function file has been designed so that you will not have direct access to the password matrix itself; you can only access some limited tools to check your guess.
A template solution m-file script that you will complete as your solution submission. You may only change 2 specific areas of the template m-file:
Line #17, where you PW_Decode solution matrix is defined
The section starting at Line #28, where you are asked to insert your PW decoding procedure
Using these two documents, you are to design, write, and test a PW decoding procedure to determine what the correct PW matrix is.
TemplateSolution.m:
% Template Bonus Solution -------------------------------------------------
clear all
close all
clc
Time = zeros(1,10); % Vector containing 10 elapsed times to complete PW
% decode process
for T =1:10 % Repeat decode procedure for 10 DIFFERENT PW matrix
[Check1, Check2] = BonusPW();
% Generate the random Password matrix and returns
% the Parent function output
% *************************************************************************
% You can edit line #17 ===================================================
PW_Decode = []; % Your decoded PW matrix needs to be saved in
% the variable PW_Decode
% =========================================================================
% *************************************************************************
tic; % Start decode time stopwatch
while ~Check2(PW_Decode)
% *****************************************************************
% Insert your solution code between HERE ==========================
for jj=1:4;for kk=1:500;Matrix(jj,kk)=PW_Decode(jj,kk);end;end
% and HERE ========================================================
% *****************************************************************
end
Time(T) = toc; % Stop decode time stopwatch
end
MeanT = mean(Time); % Average time of PW matric decode process
disp(['Individual Decode Times: ' num2str(Time)]);
disp(['Average Decode Time: ' num2str(MeanT)]);
Function File:
function [CheckElement, CheckPW] = BonusPW()
PW = zeros(4,500);
PW(1,:) = randperm(1000,500) - 1; % Lines 5 - 8 randomly generate the
PW(2,:) = randperm(1000,500) - 1; % numeric password matrix, PW
PW(3,:) = randperm(1000,500) + 250;
PW(4,:) = randperm(1000,500) - 2000;
CheckElement = @isElement; % CheckElement is a handle to child
% function isElement()
CheckPW = @isPW; % CheckPW is a handle to the child
% function isPW()
function Correct = isElement(Guess, numPW, Index)
% This child function checks whether a scalar integer Guess is
% equal to a specific element contained in PW
Correct = false;
if size(Guess == [1,1])
if PW(numPW,Index) == Guess
Correct = true;
end
end
end
function Correct = isPW(Guess)
Correct = false;
if size(Guess) == size(PW)
if PW == Guess
Correct = true;
end
end
end
end
Please EXPLAIN your solution if you find one!
Thanks
Explanation / Answer
The function file I provided generates a password.The script file will edits the lines 17 and 28. Line 17 will says PW_Decode = [].the randomly generated passwords mean that guesses are made. So,by editing the line pwd guess and By editing the lines 17 and 28 we can be able to "crack" the randomly generated password made by the function file.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.