# I am trying to decode an encrypted message

16 ビュー (過去 30 日間)
Kevin Junior 2013 年 10 月 15 日
コメント済み: Kevin Junior 2013 年 10 月 19 日
Here are the files that I have to use.
% First file
encodedString = 'aasfu aic talputte balde';
encryptionKey = [6,7];
% encryptionKey is an array that stores the m-value used in
% perfectMShuffle() function and the number of shuffles performed.
% write the rest of the code, which has to be done in two parts:
% 1) determine the cycle length of the m-shuffle, i.e. how many shuffles
% (including the first one) are needed to return the string to its original
% order
% 2) complete the shuffle cycle on the encoded string to reveal the secret
% message
% Second file
function outString = perfectMShuffle(inString,m)
% This function shuffles the characters in the inString by picking 1st,
% m+1st, 2m+1st characters till it reaches the end, then picking 2nd, m+2nd
% 2m+2nd etc.
% Examples:
% perfectMShuffle('abcdef',2) -> 'acebdf
So how do I approach this problem?

#### 2 件のコメント

Jan 2013 年 10 月 15 日
This looks like a homework question. For obvious reasons we will not solve this for you, otherwise you would be forced to cheat, when you submit it.
The standard procedure is that you show us, what you have tried so far and ask a specific question.
Kevin Junior 2013 年 10 月 15 日
how do I implement the outstring function here is what I have
function outString = perfectMshuffle(inString,m)
n = length(inString);
y = zeros(n,1);
m = n/2;
for k = 1:m
y(2*k-1) = inString(k);
y(2*k) = inString(k+m);
end

サインイン to comment.

### 回答 (1 件)

Walter Roberson 2013 年 10 月 15 日
What happens if you reshape() a vector into an array, transpose(), and reshape the result into a vector?

#### 3 件のコメント

Kevin Junior 2013 年 10 月 15 日
Thanks for the help I just did it,
n = length(inString);
X = n/m;
outString = reshape(reshape(inString,X,m)',n,1);
so how do I decode the encrypted message??
Walter Roberson 2013 年 10 月 19 日
Encode [1:length(inString)] using your encoding method. Then index the encrypted string by the array that resulted from that encoding.
Kevin Junior 2013 年 10 月 19 日
Thanks for the heads up again now I wrote the full program am almost there i just dont know where to add the encode[(1:length(instring)]. Here is my code
encodedString = 'aasfu aic talputte balde';
encryptionKey = [6,7];
% encryptionKey is an array that stores the m-value used in
% perfectMShuffle() function and the number of shuffles performed.
N = 1000;
cl = zeros(N/2,1);
for n = 2:2:N
ordered = [1,n]';
encodedString = ordered;
encodedString = perfectMShuffle(encodedString,encryptionKey);
counter = 1;
while any(encodedString - ordered)
encodedString = perfectMShuffle(encodedString,encryptionKey);
counter = counter + 1;
end
cl(n/2) = counter;
end

サインイン to comment.

サインイン してこの質問に回答します。

Translated by