|
On 3/23/2012 2:16 PM, Alice wrote:
> For some work I have to code a function for the Vigenere cipher, I have
> to make the keyword the same length as my message. so say my message is
> 'abcdefg' and the keyword is 'at' i need it to repeat the keyword 3
> times then have an extra 'a' on the end so it would be 'atatata'. repmat
> works but only if the message is a multiple of the key, any ideas how i
> can do this?
Wrap the logic in a function and use it.
msg='abcdefg';
key='at'
function key=buildkey(msg,base)
n=fix(length(msg),length(base));
m=rem(length('abcdefg'),length('at'));
key=repmat(key,1,n);
if m>0, key=[key base(1:m)]; end
NB: Air code, untested; salt to suit...
--
|