Assign index value to bits in cyclic order
2 views (last 30 days)
Show older comments
Hi,
I am working on implementing following logic in matlab
I calculating index variable value based on length of my ciphertext
Index Variable P=Mod(l,3) where l is length of ciphertext after converting it into binary
Say ciphertext is 11001011 01111010 10101010 10011001 01010101
This data is five bytes. So l=5 therefore p=2 ((Mod(l,3)) &
then I want to assign index variable to the bits of cipher text in cylic order based on calculated value of index variable
P=0 then
P=1 then
P=2 then after this again p=0
Operation IndexVariable,P
(11) 2
(00) 0
(10) 1
(11) 2
(01) 0
(11) 1
(10) 2
(10) 0
(10) 1
(10) 2
(10) 0
(10) 1
so on………
please provide me directions..
Thanks in Advance !!
2 Comments
Jan
on 13 Mar 2012
I understand the question until "p=2 ((Mod(l,3)) &". What does this mean? I do not get the meaning of the next sentence "the I want..." and "P=0 then P=1 then P=2 then". What is the "Operation" and what does the comma mean in "IndexVariable,P".
Accepted Answer
Andrei Bobrov
on 13 Mar 2012
s = '11001011 01111010 10101010 10011001 01010101'
p = rem(numel(regexp(s,' [01]'))+1,3)
k = (0:2)'
s1 = reshape(regexprep(s,' ',''),2,[])'
n = size(s1,1)
N = k(:,ones(fix((n+1)/3)+1,1))
P = N(find(N(:,1) == p)+(0:n-1))'
3 Comments
More Answers (0)
See Also
Categories
Find more on Encryption / Cryptography in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!